diff --git a/lib/quran-json/pull.rb b/lib/quran-json/pull.rb index f17f6a3..faeaa5c 100644 --- a/lib/quran-json/pull.rb +++ b/lib/quran-json/pull.rb @@ -55,12 +55,11 @@ class Pull http.finish end - def skip?(surah_no) - exist?(surah_no) && !options.overwrite - end - - def exist?(surah_no) - File.exist? File.join(quran_dir, options.locale, "#{surah_no}.json") + ## + # @return [Boolean] + # Returns true when a surah shouldn't be replaced + def keep?(surah_no) + exist?(surah_no) and [options.overwrite].all? { _1.equal?(false) } end private @@ -69,6 +68,10 @@ class Pull format source.http.path, source.http.vars.map { [_1.to_sym, vars[_1.to_sym]] }.to_h end + def exist?(surah_no) + File.exist? File.join(quran_dir, options.locale, "#{surah_no}.json") + end + def headers @headers ||= { "user-agent" => "quran-json (https://github.com/ReflectsLight/quran-json#readme)" diff --git a/libexec/quran-json/quran.com b/libexec/quran-json/quran.com index b26b19e..e32e09b 100755 --- a/libexec/quran-json/quran.com +++ b/libexec/quran-json/quran.com @@ -16,7 +16,7 @@ def main(argv) cmd = Pull.new(Pull.cli(argv)) cmd.keepalive do 1.upto(114) do |surah_no| - next if cmd.skip?(surah_no) + next if cmd.keep?(surah_no) rows = [] 1.upto(cmd.count[surah_no]) do |ayah_no| res = cmd.pull_ayah(surah_no, ayah_no) diff --git a/libexec/quran-json/www.searchtruth.com b/libexec/quran-json/www.searchtruth.com index ee26db9..07bc376 100755 --- a/libexec/quran-json/www.searchtruth.com +++ b/libexec/quran-json/www.searchtruth.com @@ -17,7 +17,7 @@ def main(argv) cmd = Pull.new(Pull.cli(argv)) cmd.keepalive do 1.upto(114) do |surah_no| - next if cmd.skip?(surah_no) + next if cmd.keep?(surah_no) rows = [] res = cmd.pull_surah(surah_no) rows.concat(grep(res).map.with_index(1) { [_2, _1] })