binlib/sql: sync chapter.rb with recent changes.
This commit is contained in:
parent
635e9e0d5c
commit
22a2791260
1 changed files with 9 additions and 14 deletions
|
@ -1,26 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Chapter
|
||||
CHAPTERS = JSON.parse(
|
||||
File.read(
|
||||
File.join('src', 'json', 'chapters-data.json')
|
||||
)
|
||||
)
|
||||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
@contents = JSON.parse(File.read(path))
|
||||
@metadata = @contents.shift
|
||||
@locale = File.basename(File.dirname(path))
|
||||
end
|
||||
|
||||
def number
|
||||
File.basename(@path, ".json").to_i
|
||||
Integer(@metadata["id"])
|
||||
end
|
||||
|
||||
def name
|
||||
if @locale == "ar"
|
||||
SQLUtils.escape(CHAPTERS[number - 1]['codepoints'].pack('U*'))
|
||||
SQLUtils.escape(@metadata['codepoints'].pack('U*'))
|
||||
else
|
||||
SQLUtils.escape(CHAPTERS[number - 1]['translated_name'])
|
||||
SQLUtils.escape(@metadata['translated_name'])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -28,19 +23,19 @@ class Chapter
|
|||
if @locale == "ar"
|
||||
name
|
||||
else
|
||||
SQLUtils.escape(CHAPTERS[number - 1]['transliterated_name'])
|
||||
SQLUtils.escape(@metadata['transliterated_name'])
|
||||
end
|
||||
end
|
||||
|
||||
def slug
|
||||
SQLUtils.escape(CHAPTERS[number - 1]['slug'])
|
||||
SQLUtils.escape(@metadata['slug'])
|
||||
end
|
||||
|
||||
def city
|
||||
SQLUtils.escape(CHAPTERS[number - 1]['place_of_revelation'].capitalize)
|
||||
SQLUtils.escape(@metadata['place_of_revelation'].capitalize)
|
||||
end
|
||||
|
||||
def verses
|
||||
JSON.parse(File.read(@path)).map { Verse.new(*_1) }
|
||||
@contents.map { Verse.new(*_1) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue