rubocop-ify

This commit is contained in:
0x1eef 2022-07-16 16:19:50 -03:00
parent ddac69f0a8
commit 2c521b6d70
8 changed files with 52 additions and 17 deletions

26
.rubocop.yml Normal file
View file

@ -0,0 +1,26 @@
##
# Plugins
require:
- standard
##
# Defaults: standard-rb
inherit_gem:
standard: config/base.yml
AllCops:
TargetRubyVersion: 3.1
##
# Enabled cops
Style/FrozenStringLiteralComment:
Enabled: true
##
# Disabled cops
Layout/MultilineMethodCallIndentation:
Enabled: false
Layout/ArgumentAlignment:
Enabled: false
Style/LambdaCall:
Enabled: false

View file

@ -1,11 +1,16 @@
#!/usr/bin/env ruby
#
# frozen_string_literal: true
##
# This script requests each verse, in each chapter
# of The Qur'an - in the Arabic language. The content
# is requested from the https://sacred-texts.com website.
#
# Each chapter is then saved in a JSON file, for example:
# "src/json/ar/1.json", "src/json/ar/2.json", etc.
##
# Set process name
$0 = "pull-arabic"
##
@ -33,7 +38,7 @@ line = IO::Line.new($stdout)
find_content = ->(res) do
html = Nokogiri::HTML(res.body)
html.css("table tr td p[align=RIGHT]").map do
_1.text.gsub(/[0-9]+/, '')
_1.text.gsub(/[0-9]+/, "")
.delete("\u200F")
.delete("\u200E")
.strip

View file

@ -1,5 +1,7 @@
#!/usr/bin/env ruby
#
# frozen_string_literal: true
##
# This script requests each verse, in each chapter
# of The Qur'an - in the English language. The content
# is requested from the https://quran.com website.

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
##
# This script requests each verse, in each chapter
@ -104,9 +105,7 @@ end
sleep 0.1
end
File.write(final_dest, JSON.pretty_generate(rows))
print Paint["OK: ", :green, :bold], final_dest.sub(ENV['HOME'], ''), "\n"
print Paint["OK: ", :green, :bold], final_dest.sub(ENV["HOME"], ""), "\n"
sleep cool_off
print Paint["Chill for #{cool_off} seconds", :blue, :bold], "\n", "\n"
end

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
##
# This script requests each verse, in each chapter
@ -80,7 +81,7 @@ end
def extract_verse!(res, remove_suratu)
doc = Nokogiri::HTML(res.body)
verse = doc.css(".ayah .translate").first
(remove_suratu ? verse.text.sub(/^Suratu [\w\-.]+/, '') : verse.text).strip
(remove_suratu ? verse.text.sub(/^Suratu [\w\-.]+/, "") : verse.text).strip
end
##
@ -103,9 +104,7 @@ end
end
end
File.write(final_dest, JSON.pretty_generate(rows))
print Paint["OK: ", :green, :bold], final_dest.sub(ENV['HOME'], ''), "\n"
print Paint["OK: ", :green, :bold], final_dest.sub(ENV["HOME"], ""), "\n"
sleep cool_off
print Paint["Chill for #{cool_off} seconds", :blue, :bold], "\n", "\n"
end

View file

@ -1,10 +1,12 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require "json"
require "erb"
module SQLUtils
module_function
def escape(str)
char = "'"
char + str.gsub(char, char * 2) + char
@ -20,8 +22,8 @@ class Language
def chapters
Dir.glob(File.join(
__dir__, "..", "src",
"json", @locale, "*.json"
__dir__, "..", "src",
"json", @locale, "*.json"
)).map { Chapter.new(_1) }.sort_by(&:number)
end
end
@ -32,7 +34,7 @@ class Chapter
end
def number
File.basename(@path, '.json').to_i
File.basename(@path, ".json").to_i
end
def verses
@ -49,10 +51,9 @@ class Verse
end
end
base_dir = File.join(__dir__, "..", "src", "sql")
template = File.read File.join(base_dir, "seed.sql.erb")
languages = %w(ar en pt fa).map { Language.new(_1) }
base_dir = File.join(__dir__, "..", "src", "sql")
template = File.read File.join(base_dir, "seed.sql.erb")
languages = %w[ar en pt fa].map { Language.new(_1) }
result = ERB.new(template)
.result_with_hash(chapter_id: 1, languages:)
.each_line.map(&:strip)

View file

@ -1,4 +1,5 @@
# frozen_string_literal: true
class IO::Line
require "io/console"
attr_reader :io

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
gem "nokogiri", "~> 1.13"
gem "paint", "~> 2.2"
gem "json", "~> 2.6"