Replace Pull#skip?
with Pull#keep?
This commit is contained in:
parent
133d1374d4
commit
a35e0ed6de
3 changed files with 11 additions and 8 deletions
|
@ -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)"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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] })
|
||||
|
|
Loading…
Reference in a new issue