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

View file

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

View file

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

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
## ##
# This script requests each verse, in each chapter # This script requests each verse, in each chapter
@ -80,7 +81,7 @@ end
def extract_verse!(res, remove_suratu) def extract_verse!(res, remove_suratu)
doc = Nokogiri::HTML(res.body) doc = Nokogiri::HTML(res.body)
verse = doc.css(".ayah .translate").first 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 end
## ##
@ -103,9 +104,7 @@ end
end end
end end
File.write(final_dest, JSON.pretty_generate(rows)) 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 sleep cool_off
print Paint["Chill for #{cool_off} seconds", :blue, :bold], "\n", "\n" print Paint["Chill for #{cool_off} seconds", :blue, :bold], "\n", "\n"
end end

View file

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

View file

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

View file

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