Class: ScriptureReference
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ScriptureReference
- Defined in:
- lib/generators/scripturable/templates/scripture_reference.rb
Constant Summary collapse
- REFERENCE_FORMAT =
/^(\d+)(?::(\d+))?(?::(\d+))?$/
Class Method Summary collapse
Instance Method Summary collapse
- #delimiters ⇒ Object
- #delimiters=(hash) ⇒ Object
- #end_verse ⇒ Object
- #include?(verse) ⇒ Boolean
- #scripture_verses_should_exist ⇒ Object
- #start_verse ⇒ Object
- #to_hash ⇒ Object
Class Method Details
.that_include(integer) ⇒ Object
9 10 11 |
# File 'lib/generators/scripturable/templates/scripture_reference.rb', line 9 def self.that_include(integer) where("scripture_references.start_at <= #{integer}").where("scripture_references.end_at >= #{integer}") if integer.is_a?(Fixnum) end |
Instance Method Details
#delimiters ⇒ Object
44 45 46 |
# File 'lib/generators/scripturable/templates/scripture_reference.rb', line 44 def delimiters OpenStruct.new(self.to_hash) end |
#delimiters=(hash) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/generators/scripturable/templates/scripture_reference.rb', line 22 def delimiters= hash @start_verse = ScriptureVerse.new({'book_number' => hash[:book], 'chapter_number' => hash[:start_chapter], 'verse_number' => hash[:start_verse] }) @end_verse = ScriptureVerse.new({'book_number' => hash[:book], 'chapter_number' => hash[:end_chapter], 'verse_number' => hash[:end_verse] }) self.start_at = @start_verse.to_i self.end_at = @end_verse.to_i end |
#end_verse ⇒ Object
18 19 20 |
# File 'lib/generators/scripturable/templates/scripture_reference.rb', line 18 def end_verse ScriptureVerse.new(end_at) end |
#include?(verse) ⇒ Boolean
29 30 31 |
# File 'lib/generators/scripturable/templates/scripture_reference.rb', line 29 def include?(verse) start_at < verse && verse < end_at end |
#scripture_verses_should_exist ⇒ Object
48 49 50 51 52 |
# File 'lib/generators/scripturable/templates/scripture_reference.rb', line 48 def scripture_verses_should_exist if !start_verse.exists? || !end_verse.exists? errors.add(:base, "Scripture reference does not exist") end end |
#start_verse ⇒ Object
13 14 15 |
# File 'lib/generators/scripturable/templates/scripture_reference.rb', line 13 def start_verse ScriptureVerse.new(start_at) end |
#to_hash ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generators/scripturable/templates/scripture_reference.rb', line 33 def to_hash { :book_name => start_verse.book_name, :book => start_verse.book_number, :start_chapter => start_verse.chapter_number, :start_verse => start_verse.verse_number, :end_chapter => end_verse.chapter_number, :end_verse => end_verse.verse_number } end |