Class: Wombat::Iterator
- Inherits:
-
PropertyContainer
- Object
- Hash
- PropertyContainer
- Wombat::Iterator
- Defined in:
- lib/wombat/iterator.rb
Instance Attribute Summary collapse
-
#selector ⇒ Object
Returns the value of attribute selector.
Attributes inherited from PropertyContainer
Instance Method Summary collapse
- #flatten(depth = nil) ⇒ Object
-
#initialize(selector) ⇒ Iterator
constructor
A new instance of Iterator.
- #parse ⇒ Object
- #reset ⇒ Object
Methods inherited from PropertyContainer
#all_properties, #for_each, #method_missing, #to_ary
Constructor Details
#initialize(selector) ⇒ Iterator
Returns a new instance of Iterator.
5 6 7 8 |
# File 'lib/wombat/iterator.rb', line 5 def initialize(selector) @selector = selector super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Wombat::PropertyContainer
Instance Attribute Details
#selector ⇒ Object
Returns the value of attribute selector.
3 4 5 |
# File 'lib/wombat/iterator.rb', line 3 def selector @selector end |
Instance Method Details
#flatten(depth = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wombat/iterator.rb', line 27 def flatten(depth = nil) # determine the iterator length by the biggest property array that we have length = all_properties.map(&:result).sort { |a| a.length }.last.size Array.new.tap do |a| length.times do |i| a << super(i) end end end |
#parse ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/wombat/iterator.rb', line 10 def parse raise ArgumentError.new('Must provide a block to locate property values') unless block_given? all_properties.each do |p| p.result ||= [] result = yield p if result result = p.callback ? p.callback.call(result) : result p.result << result end end end |
#reset ⇒ Object
23 24 25 |
# File 'lib/wombat/iterator.rb', line 23 def reset all_properties.each { |p| p.reset } end |