Class: Bible::BibleRefParser::Chapters
- Inherits:
-
Object
- Object
- Bible::BibleRefParser::Chapters
- Includes:
- RangeComparisons
- Defined in:
- lib/bible/parser.rb
Overview
Represents range or discontinuous series of chaptesr
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #==(value) ⇒ Object
- #[](index) ⇒ Object
-
#each ⇒ Object
Returns Chapter objects for each chapter, or -1 if “end of chapters” is indicated.
- #fixup ⇒ Object
-
#initialize(book) ⇒ Chapters
constructor
A new instance of Chapters.
- #inspect ⇒ Object
- #last ⇒ Object
- #length ⇒ Object
Methods included from RangeComparisons
Constructor Details
#initialize(book) ⇒ Chapters
Returns a new instance of Chapters.
535 536 537 538 |
# File 'lib/bible/parser.rb', line 535 def initialize(book) @chapters = [] @book = book end |
Instance Method Details
#<<(value) ⇒ Object
552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/bible/parser.rb', line 552 def <<(value) unless value.nil? || @chapters.empty? || @chapters.last.nil? || value == -1 raise "Cannot add a chapter reference in reverse order" if @chapters.last > value unless @chapters.last.chapter_number == value @chapters.last.succ.upto(value) { |c| @chapters << c } end else @chapters << value end end |
#==(value) ⇒ Object
577 578 579 |
# File 'lib/bible/parser.rb', line 577 def ==(value) compare_ranges(@chapters, value, "chapters") end |
#[](index) ⇒ Object
573 574 575 |
# File 'lib/bible/parser.rb', line 573 def [](index) return @chapters.compact[index] end |
#each ⇒ Object
Returns Chapter objects for each chapter, or -1 if “end of chapters” is indicated. If chapters is empty, will be a no-op
591 592 593 594 595 596 |
# File 'lib/bible/parser.rb', line 591 def each return if @chapters.empty? @chapters.each { |chapter| yield chapter unless chapter.nil? } end |
#fixup ⇒ Object
540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/bible/parser.rb', line 540 def fixup if @chapters.last == -1 book = Books[@book.book_symbol] @chapters.pop @chapters.last.succ.upto(book.chapters.last) do |c| @chapters << c end end @chapters.compact.each { |c| c.fixup } end |
#inspect ⇒ Object
581 582 583 584 585 586 587 |
# File 'lib/bible/parser.rb', line 581 def inspect @chapters.inject("") { |val, c| val << "," unless val.empty? val << c.inspect unless c.nil? val } end |
#last ⇒ Object
569 570 571 |
# File 'lib/bible/parser.rb', line 569 def last @chapters.last end |
#length ⇒ Object
565 566 567 |
# File 'lib/bible/parser.rb', line 565 def length @chapters.length end |