Class: AudioBookCreator::CascadingArray
- Inherits:
-
Object
- Object
- AudioBookCreator::CascadingArray
- Includes:
- Enumerable
- Defined in:
- lib/audio_book_creator/cascading_array.rb
Overview
this fetching from the first array, fetching from the second if nothing is available
Instance Attribute Summary collapse
-
#all ⇒ Object
Returns the value of attribute all.
-
#alt ⇒ Object
Array the alternative array if this one is empty.
-
#main ⇒ Object
Array the alternative array if this one is empty.
Instance Method Summary collapse
- #add_chapter(value) ⇒ Object
- #add_page(value) ⇒ Object
- #add_unique_chapter(value) ⇒ Object
- #add_unique_page(value) ⇒ Object
- #each(&block) ⇒ Object
-
#include?(value) ⇒ Boolean
note: ever included.
-
#initialize(main, alt) ⇒ CascadingArray
constructor
A new instance of CascadingArray.
- #shift ⇒ Object
Constructor Details
#initialize(main, alt) ⇒ CascadingArray
Returns a new instance of CascadingArray.
18 19 20 21 22 |
# File 'lib/audio_book_creator/cascading_array.rb', line 18 def initialize(main, alt) @all = Set.new.merge(main).merge(alt) @main = main @alt = alt end |
Instance Attribute Details
#all ⇒ Object
Returns the value of attribute all.
16 17 18 |
# File 'lib/audio_book_creator/cascading_array.rb', line 16 def all @all end |
#alt ⇒ Object
Returns Array the alternative array if this one is empty.
14 15 16 |
# File 'lib/audio_book_creator/cascading_array.rb', line 14 def alt @alt end |
#main ⇒ Object
Returns Array the alternative array if this one is empty.
10 11 12 |
# File 'lib/audio_book_creator/cascading_array.rb', line 10 def main @main end |
Instance Method Details
#add_chapter(value) ⇒ Object
24 25 26 27 |
# File 'lib/audio_book_creator/cascading_array.rb', line 24 def add_chapter(value) all << value alt << value end |
#add_page(value) ⇒ Object
33 34 35 36 |
# File 'lib/audio_book_creator/cascading_array.rb', line 33 def add_page(value) all << value main << value end |
#add_unique_chapter(value) ⇒ Object
29 30 31 |
# File 'lib/audio_book_creator/cascading_array.rb', line 29 def add_unique_chapter(value) add_chapter(value) unless include?(value) end |
#add_unique_page(value) ⇒ Object
38 39 40 |
# File 'lib/audio_book_creator/cascading_array.rb', line 38 def add_unique_page(value) add_page(value) unless include?(value) end |
#each(&block) ⇒ Object
42 43 44 45 46 |
# File 'lib/audio_book_creator/cascading_array.rb', line 42 def each(&block) return enum_for unless block_given? main.each(&block) alt.each(&block) end |
#include?(value) ⇒ Boolean
note: ever included
49 50 51 |
# File 'lib/audio_book_creator/cascading_array.rb', line 49 def include?(value) all.include?(value) end |
#shift ⇒ Object
53 54 55 |
# File 'lib/audio_book_creator/cascading_array.rb', line 53 def shift main.shift || alt.shift end |