From 2c521b6d706fdada99510deaa0415bfa4e49bdb5 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sat, 16 Jul 2022 16:19:50 -0300 Subject: [PATCH] rubocop-ify --- .rubocop.yml | 26 ++++++++++++++++++++++++++ bin/json/pull-arabic | 9 +++++++-- bin/json/pull-english | 4 +++- bin/json/pull-farsi | 5 ++--- bin/json/pull-portuguese | 7 +++---- bin/sql/create-sql-seed-file | 15 ++++++++------- binlib/io/line.rb | 1 + gem.deps.rb | 2 ++ 8 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..62d9f2f --- /dev/null +++ b/.rubocop.yml @@ -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 diff --git a/bin/json/pull-arabic b/bin/json/pull-arabic index 6ab5c6e..3ea8d90 100755 --- a/bin/json/pull-arabic +++ b/bin/json/pull-arabic @@ -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 diff --git a/bin/json/pull-english b/bin/json/pull-english index 9fa1c05..93594b0 100755 --- a/bin/json/pull-english +++ b/bin/json/pull-english @@ -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. diff --git a/bin/json/pull-farsi b/bin/json/pull-farsi index e483318..84fa98b 100755 --- a/bin/json/pull-farsi +++ b/bin/json/pull-farsi @@ -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 - - diff --git a/bin/json/pull-portuguese b/bin/json/pull-portuguese index bdff71b..7ca7c58 100755 --- a/bin/json/pull-portuguese +++ b/bin/json/pull-portuguese @@ -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 - - diff --git a/bin/sql/create-sql-seed-file b/bin/sql/create-sql-seed-file index d7a9d8e..9d7931f 100755 --- a/bin/sql/create-sql-seed-file +++ b/bin/sql/create-sql-seed-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) diff --git a/binlib/io/line.rb b/binlib/io/line.rb index 50fcb9d..31ee0aa 100644 --- a/binlib/io/line.rb +++ b/binlib/io/line.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class IO::Line require "io/console" attr_reader :io diff --git a/gem.deps.rb b/gem.deps.rb index ee02352..1a1040b 100644 --- a/gem.deps.rb +++ b/gem.deps.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + gem "nokogiri", "~> 1.13" gem "paint", "~> 2.2" gem "json", "~> 2.6"