Add Quran::JSON namespace
This commit is contained in:
parent
b117ae8ce6
commit
5a2d637644
6 changed files with 19 additions and 14 deletions
|
@ -21,11 +21,11 @@ def main(argv)
|
||||||
libexec_dir = File.join(root_dir, "libexec", "quran-json")
|
libexec_dir = File.join(root_dir, "libexec", "quran-json")
|
||||||
share_dir = File.join(root_dir, "share", "quran-json", "data")
|
share_dir = File.join(root_dir, "share", "quran-json", "data")
|
||||||
sources = JSON.parse(File.binread(File.join(share_dir, "sources.json")))
|
sources = JSON.parse(File.binread(File.join(share_dir, "sources.json")))
|
||||||
require File.join(lib_dir, "pull")
|
require File.join(lib_dir, "quran", "json")
|
||||||
|
|
||||||
case argv[0]
|
case argv[0]
|
||||||
when "pull"
|
when "pull"
|
||||||
options = Pull.cli(argv[1..])
|
options = Quran::JSON::Pull.cli(argv[1..])
|
||||||
sources.each do |locale, source|
|
sources.each do |locale, source|
|
||||||
case options.locale
|
case options.locale
|
||||||
when locale
|
when locale
|
||||||
|
|
6
lib/quran-json/quran/json.rb
Normal file
6
lib/quran-json/quran/json.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module Quran
|
||||||
|
module JSON
|
||||||
|
require_relative "json/cmd"
|
||||||
|
require_relative "json/pull"
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,10 +1,10 @@
|
||||||
module Command
|
module Quran::JSON::Cmd
|
||||||
require "ryo"
|
require "ryo"
|
||||||
require "json"
|
require "json"
|
||||||
require "io/line"
|
require "io/line"
|
||||||
|
|
||||||
def root_dir
|
def root_dir
|
||||||
File.realpath File.join(__dir__, "..", "..")
|
File.realpath File.join(__dir__, "..", "..", "..", "..")
|
||||||
end
|
end
|
||||||
|
|
||||||
def share_dir
|
def share_dir
|
|
@ -1,11 +1,10 @@
|
||||||
class Pull
|
class Quran::JSON::Pull
|
||||||
require "ryo"
|
require "ryo"
|
||||||
require "json"
|
require "json"
|
||||||
require "net/http"
|
require "net/http"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
require "optparse"
|
require "optparse"
|
||||||
require_relative "command"
|
include Quran::JSON::Cmd
|
||||||
include Command
|
|
||||||
include FileUtils
|
include FileUtils
|
||||||
|
|
||||||
attr_reader :options,
|
attr_reader :options,
|
||||||
|
@ -62,7 +61,7 @@ class Pull
|
||||||
|
|
||||||
##
|
##
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
# Returns true when a surah shouldn't be replaced
|
# Returns true when a surah shouldn't be replaced, or updated
|
||||||
def keep?(surah_no)
|
def keep?(surah_no)
|
||||||
exist?(surah_no) and [options.replace, options.update].all? { _1.equal?(false) }
|
exist?(surah_no) and [options.replace, options.update].all? { _1.equal?(false) }
|
||||||
end
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
lib_dir = File.realpath File.join(__dir__, "..", "..", "lib", "quran-json")
|
lib_dir = File.realpath File.join(__dir__, "..", "..", "lib", "quran-json")
|
||||||
require File.join(lib_dir, "pull")
|
require File.join(lib_dir, "quran", "json")
|
||||||
require "optparse"
|
require "optparse"
|
||||||
require "nokogiri"
|
require "nokogiri"
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ end
|
||||||
##
|
##
|
||||||
# main
|
# main
|
||||||
def main(argv)
|
def main(argv)
|
||||||
cmd = Pull.new(Pull.cli(argv))
|
cmd = Quran::JSON::Pull.new(Quran::JSON::Pull.cli(argv))
|
||||||
cmd.keepalive do
|
cmd.keepalive do
|
||||||
1.upto(114) do |surah_no|
|
1.upto(114) do |surah_no|
|
||||||
if cmd.keep?(surah_no)
|
if cmd.keep?(surah_no)
|
||||||
|
@ -21,7 +21,7 @@ def main(argv)
|
||||||
elsif cmd.options.update
|
elsif cmd.options.update
|
||||||
cmd.update(surah_no)
|
cmd.update(surah_no)
|
||||||
else
|
else
|
||||||
rows = []
|
rows = [nil]
|
||||||
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)
|
||||||
rows.push([ayah_no, grep(res)])
|
rows.push([ayah_no, grep(res)])
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
lib_dir = File.realpath File.join(__dir__, "..", "..", "lib", "quran-json")
|
lib_dir = File.realpath File.join(__dir__, "..", "..", "lib", "quran-json")
|
||||||
require File.join(lib_dir, "pull")
|
require File.join(lib_dir, "quran", "json")
|
||||||
require "optparse"
|
require "optparse"
|
||||||
require "nokogiri"
|
require "nokogiri"
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ end
|
||||||
##
|
##
|
||||||
# main
|
# main
|
||||||
def main(argv)
|
def main(argv)
|
||||||
cmd = Pull.new(Pull.cli(argv))
|
cmd = Quran::JSON::Pull.new(Quran::JSON::Pull.cli(argv))
|
||||||
cmd.keepalive do
|
cmd.keepalive do
|
||||||
1.upto(114) do |surah_no|
|
1.upto(114) do |surah_no|
|
||||||
if cmd.keep?(surah_no)
|
if cmd.keep?(surah_no)
|
||||||
|
@ -22,7 +22,7 @@ def main(argv)
|
||||||
elsif cmd.options.update
|
elsif cmd.options.update
|
||||||
cmd.update(surah_no)
|
cmd.update(surah_no)
|
||||||
else
|
else
|
||||||
rows = []
|
rows = [nil]
|
||||||
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] })
|
||||||
cmd.line.rewind.print "Surah #{surah_no} [#{surah_no}/114]"
|
cmd.line.rewind.print "Surah #{surah_no} [#{surah_no}/114]"
|
||||||
|
|
Loading…
Reference in a new issue