Class: ScriptureVerse

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/scripturable/templates/scripture_verse.rb

Constant Summary collapse

SCRIPTURE_VERSE_FORMAT =

SCRIPTURE_VERSE_FORMAT = /^(d+)(?::(d+))?(?::(d+))?$/ #rubular.com/r/7axgNYfYiK

/^(\d+):(\d+):(\d+)$/

Instance Method Summary collapse

Constructor Details

#initialize(values = nil) ⇒ ScriptureVerse

Returns a new instance of ScriptureVerse.



6
7
8
9
10
11
12
13
# File 'lib/generators/scripturable/templates/scripture_verse.rb', line 6

def initialize values=nil
  values = parse_verse(values) if values.is_a?(String)
  values = resolve values if values.is_a?(Fixnum)
  if values.is_a?(Hash)
    values.each{ |k, v| values[k] = v.to_i unless v.nil? }
    @book_number, @chapter_number, @verse_number = values['book_number'], values['chapter_number'], values['verse_number']
  end
end

Instance Method Details

#book_nameObject



27
28
29
# File 'lib/generators/scripturable/templates/scripture_verse.rb', line 27

def book_name
  book_hash['name'] unless book_hash.nil?
end

#book_numberObject



15
16
17
# File 'lib/generators/scripturable/templates/scripture_verse.rb', line 15

def book_number
  @book_number
end

#chapter_numberObject



19
20
21
# File 'lib/generators/scripturable/templates/scripture_verse.rb', line 19

def chapter_number
  @chapter_number
end

#exists?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/generators/scripturable/templates/scripture_verse.rb', line 51

def exists?
  book_exists? && chapter_exists? && verse_exists?
end

#resolve(number) ⇒ Object



44
45
46
47
48
49
# File 'lib/generators/scripturable/templates/scripture_verse.rb', line 44

def resolve number
  resolution = {}
  quotient, resolution['verse_number'] = number.divmod(1000) 
  resolution['book_number'], resolution['chapter_number'] = (quotient).divmod(1000) 
  resolution
end

#to_hashObject



31
32
33
34
35
36
37
38
# File 'lib/generators/scripturable/templates/scripture_verse.rb', line 31

def to_hash
  {
    :book_number => book_number,
    :chapter_number => chapter_number,
    :verse_number => verse_number,
    :book_name => book_name
  }
end

#to_iObject



40
41
42
# File 'lib/generators/scripturable/templates/scripture_verse.rb', line 40

def to_i
  @book_number * 1000000 + @chapter_number * 1000 + @verse_number
end

#verse_numberObject



23
24
25
# File 'lib/generators/scripturable/templates/scripture_verse.rb', line 23

def verse_number
  @verse_number
end