Class: Bible::BookInfo

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#abbreviationsObject

Symbol naming book this information is about



30
31
32
# File 'lib/bible/parser.rb', line 30

def abbreviations
  @abbreviations
end

#bookObject

Symbol naming book this information is about



30
31
32
# File 'lib/bible/parser.rb', line 30

def book
  @book
end

#chaptersObject

Symbol naming book this information is about



30
31
32
# File 'lib/bible/parser.rb', line 30

def chapters
  @chapters
end

Class Method Details

.[](book) ⇒ Object

Get a specific book by passing a symbol representing its name



94
95
96
# File 'lib/bible/parser.rb', line 94

def self.[](book)
  return all_books[all_books.index(book)]
end

.all_booksObject

Array of all books defined



89
90
91
# File 'lib/bible/parser.rb', line 89

def self.all_books
  @@all_books
end

Instance Method Details

#<=>(value) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bible/parser.rb', line 38

def <=>(value)
  if value.respond_to?(:book)
    oidx = BookInfo.all_books.index(value.book)
  elsif value.is_a?(String)
    oidx = BookInfo.all_books.index(value.to_sym)
  elsif value.is_a?(Symbol)
    oidx = BookInfo.all_books.index(value.to_s)
  else
    raise "Don't know how to compare BookInfo to #{value.inspect}"
  end

  return BookInfo.all_books.index(@book) <=> oidx
end

#==(value) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/bible/parser.rb', line 78

def ==(value)
  if value.respond_to?(:book)
    return value.book == @book
  elsif value.respond_to?(:to_s)
    return @book.to_s == value.to_s || Books[value.to_s].book == @book
  else
    false
  end
end

#[](value) ⇒ Object

Get the nth chapter (0 based)



63
64
65
# File 'lib/bible/parser.rb', line 63

def [](value)
  @chapter_info[value]
end

#succObject

Returns the BookInfo of the next book from this book



33
34
35
36
# File 'lib/bible/parser.rb', line 33

def succ
  idx = BookInfo.all_books.index(@book)
  BookInfo.all_books[idx + 1] unless idx.nil?
end

#upto(b) ⇒ Object

Yields the BookInfo of each book, including this one, up to the next book.



53
54
55
56
57
58
59
60
# File 'lib/bible/parser.rb', line 53

def upto(b)
  idx = BookInfo.all_books.index(@book)
  endIdx = BookInfo.all_books.index(b)
  while idx <= endIdx
    yield BookInfo.all_books[idx]
    idx += 1
  end
end