Class: TupleList
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #each ⇒ Object
-
#initialize(required_keys, args = {}) ⇒ TupleList
constructor
A new instance of TupleList.
- #next ⇒ Object
Constructor Details
#initialize(required_keys, args = {}) ⇒ TupleList
Returns a new instance of TupleList.
6 7 8 9 10 11 12 |
# File 'lib/tuplelist.rb', line 6 def initialize(required_keys, args = {}) @keys = required_keys @current_tuple = {} @tuple_list = [] @ignore = (args.delete :ignore) || false end |
Instance Attribute Details
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
2 3 4 |
# File 'lib/tuplelist.rb', line 2 def keys @keys end |
Instance Method Details
#[]=(key, value) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/tuplelist.rb', line 14 def []=(key, value) if @keys.include? key @current_tuple[key] = value else raise "Unspecified key '#{key}' entered" unless @ignore end end |
#each ⇒ Object
28 29 30 31 32 |
# File 'lib/tuplelist.rb', line 28 def each @tuple_list.each do |tuple_hash| yield tuple_hash.values_at(*@keys) end end |
#next ⇒ Object
22 23 24 25 26 |
# File 'lib/tuplelist.rb', line 22 def next raise "No keys for #{@current_tuple.keys | @keys} specified" unless @current_tuple.length == @keys.length @tuple_list << @current_tuple @current_tuple = {} end |