Replace Pull#skip? with Pull#keep?

This commit is contained in:
0x1eef 2023-02-13 02:24:46 -03:00
parent 133d1374d4
commit a35e0ed6de
3 changed files with 11 additions and 8 deletions

View file

@ -55,12 +55,11 @@ class Pull
http.finish http.finish
end end
def skip?(surah_no) ##
exist?(surah_no) && !options.overwrite # @return [Boolean]
end # Returns true when a surah shouldn't be replaced
def keep?(surah_no)
def exist?(surah_no) exist?(surah_no) and [options.overwrite].all? { _1.equal?(false) }
File.exist? File.join(quran_dir, options.locale, "#{surah_no}.json")
end end
private private
@ -69,6 +68,10 @@ class Pull
format source.http.path, source.http.vars.map { [_1.to_sym, vars[_1.to_sym]] }.to_h format source.http.path, source.http.vars.map { [_1.to_sym, vars[_1.to_sym]] }.to_h
end end
def exist?(surah_no)
File.exist? File.join(quran_dir, options.locale, "#{surah_no}.json")
end
def headers def headers
@headers ||= { @headers ||= {
"user-agent" => "quran-json (https://github.com/ReflectsLight/quran-json#readme)" "user-agent" => "quran-json (https://github.com/ReflectsLight/quran-json#readme)"

View file

@ -16,7 +16,7 @@ def main(argv)
cmd = Pull.new(Pull.cli(argv)) cmd = Pull.new(Pull.cli(argv))
cmd.keepalive do cmd.keepalive do
1.upto(114) do |surah_no| 1.upto(114) do |surah_no|
next if cmd.skip?(surah_no) next if cmd.keep?(surah_no)
rows = [] rows = []
1.upto(cmd.count[surah_no]) do |ayah_no| 1.upto(cmd.count[surah_no]) do |ayah_no|
res = cmd.pull_ayah(surah_no, ayah_no) res = cmd.pull_ayah(surah_no, ayah_no)

View file

@ -17,7 +17,7 @@ def main(argv)
cmd = Pull.new(Pull.cli(argv)) cmd = Pull.new(Pull.cli(argv))
cmd.keepalive do cmd.keepalive do
1.upto(114) do |surah_no| 1.upto(114) do |surah_no|
next if cmd.skip?(surah_no) next if cmd.keep?(surah_no)
rows = [] rows = []
res = cmd.pull_surah(surah_no) res = cmd.pull_surah(surah_no)
rows.concat(grep(res).map.with_index(1) { [_2, _1] }) rows.concat(grep(res).map.with_index(1) { [_2, _1] })