Class: Kj::Verse
Instance Attribute Summary collapse
- #chapter ⇒ Object
-
#chapter_id ⇒ Object
Returns the value of attribute chapter_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#number ⇒ Object
Returns the value of attribute number.
-
#page ⇒ Object
Returns the value of attribute page.
Class Method Summary collapse
- .count ⇒ Object
- .page(page) ⇒ Object
- .page_count ⇒ Object
- .percent(decimal) ⇒ Object
- .random ⇒ Object
Instance Method Summary collapse
- #book_name ⇒ Object
- #book_permalink ⇒ Object
- #chapter_number ⇒ Object
-
#initialize(args) ⇒ Verse
constructor
A new instance of Verse.
- #next ⇒ Object
- #prev ⇒ Object
- #text ⇒ Object
- #title ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args) ⇒ Verse
Returns a new instance of Verse.
10 11 12 13 14 |
# File 'lib/kj/verse.rb', line 10 def initialize(args) args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end end |
Instance Attribute Details
#chapter ⇒ Object
50 51 52 53 54 55 |
# File 'lib/kj/verse.rb', line 50 def chapter @chapter ||= begin c = Db.query("SELECT id, book_id, number FROM chapters WHERE id = ?", [chapter_id], true) Chapter.new(id: c['id'], book_id: c['book_id'], number: c['number']) end end |
#chapter_id ⇒ Object
Returns the value of attribute chapter_id.
7 8 9 |
# File 'lib/kj/verse.rb', line 7 def chapter_id @chapter_id end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/kj/verse.rb', line 7 def id @id end |
#number ⇒ Object
Returns the value of attribute number.
7 8 9 |
# File 'lib/kj/verse.rb', line 7 def number @number end |
#page ⇒ Object
Returns the value of attribute page.
7 8 9 |
# File 'lib/kj/verse.rb', line 7 def page @page end |
Class Method Details
.count ⇒ Object
20 21 22 |
# File 'lib/kj/verse.rb', line 20 def self.count 31102 end |
.page(page) ⇒ Object
45 46 47 48 |
# File 'lib/kj/verse.rb', line 45 def self.page(page) verses = Db.query("SELECT id, chapter_id, number, page FROM verses WHERE page = ?", [page]) verses.map{|verse| new(id: verse['id'], chapter_id: verse['chapter_id'], number: verse['number'], page: verse['page'])} end |
.page_count ⇒ Object
41 42 43 |
# File 'lib/kj/verse.rb', line 41 def self.page_count 1609 end |
.percent(decimal) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kj/verse.rb', line 29 def self.percent(decimal) if decimal.round(3) <= 0 verse_id = 1 elsif decimal.round(3) >= 1 verse_id = count else verse_id = (count * decimal).round end verse = Db.query("SELECT id, chapter_id, number, page FROM verses WHERE id = ?", [verse_id], true) new(id: verse['id'], chapter_id: verse['chapter_id'], number: verse['number'], page: verse['page']) end |
Instance Method Details
#book_name ⇒ Object
61 62 63 |
# File 'lib/kj/verse.rb', line 61 def book_name chapter.book_name end |
#book_permalink ⇒ Object
65 66 67 |
# File 'lib/kj/verse.rb', line 65 def book_permalink chapter.book_permalink end |
#chapter_number ⇒ Object
57 58 59 |
# File 'lib/kj/verse.rb', line 57 def chapter_number chapter.number end |
#next ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/kj/verse.rb', line 73 def next @next ||= begin v = Db.query("SELECT id, chapter_id, text, number, page FROM verses WHERE id = ?", [id + 1], true) self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'], page: v['page']) rescue Kj::Iniquity v = Db.query("SELECT id, chapter_id, text, number, page FROM verses WHERE id = ?", [1], true) self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'], page: v['page']) end end |
#prev ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/kj/verse.rb', line 83 def prev @prev ||= begin v = Db.query("SELECT id, chapter_id, text, number, page FROM verses WHERE id = ?", [id - 1], true) self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'], page: v['page']) rescue Kj::Iniquity v = Db.query("SELECT id, chapter_id, text, number, page FROM verses WHERE id = ?", [self.class.count], true) self.class.new(id: v['id'], chapter_id: v['chapter_id'], text: v['text'], number: v['number'], page: v['page']) end end |
#text ⇒ Object
93 94 95 96 97 98 |
# File 'lib/kj/verse.rb', line 93 def text @text ||= begin verse = Db.query("SELECT text FROM verses WHERE id = ?", [id], true) verse['text'] end end |
#title ⇒ Object
16 17 18 |
# File 'lib/kj/verse.rb', line 16 def title "#{book_name} #{chapter_number}:#{number}" end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/kj/verse.rb', line 69 def to_s text end |