Class: ActsAsScriptural

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_scriptural.rb

Defined Under Namespace

Classes: AbbreviationLookup, Bible, Book, Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActsAsScriptural

Returns a new instance of ActsAsScriptural.



5
6
7
# File 'lib/acts_as_scriptural.rb', line 5

def initialize
  @chapters = Array.new
end

Instance Attribute Details

#chaptersObject

Returns the value of attribute chapters.



3
4
5
# File 'lib/acts_as_scriptural.rb', line 3

def chapters
  @chapters
end

#parsedObject

Returns the value of attribute parsed.



3
4
5
# File 'lib/acts_as_scriptural.rb', line 3

def parsed
  @parsed
end

Instance Method Details

#add_chapters(parsed_reference) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/acts_as_scriptural.rb', line 20

def add_chapters(parsed_reference)
  for i in parsed_reference.first_book_index..parsed_reference.last_book_index do

    if (i == parsed_reference.first_book_index)
      first_chapter = parsed_reference.first_chapter
    else
      first_chapter = 1
    end

    if (i == parsed_reference.last_book_index)
      last_chapter = parsed_reference.last_chapter
    else
      last_chapter = bible.chapters_in_book(i)
    end

    for j in first_chapter..last_chapter
      @chapters << [i, j]
    end
  end
end

#bibleObject



41
42
43
# File 'lib/acts_as_scriptural.rb', line 41

def bible
  @bible || Bible.new
end

#lookupObject



45
46
47
# File 'lib/acts_as_scriptural.rb', line 45

def lookup
  @lookup || AbbreviationLookup.new
end

#parse(str) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/acts_as_scriptural.rb', line 9

def parse(str)
  unless str.nil?
    references = str.split(',')
    references.each do |ref| 
      parsed_reference = Parser.new.parse_reference(ref)
      add_chapters(parsed_reference) if parsed_reference
    end
  end
  self
end