Class: ExpectedResultSet
- Inherits:
-
Object
- Object
- ExpectedResultSet
- Defined in:
- lib/expected_result_set.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #add_fixture(*fixture_map) ⇒ Object
- #get_value_from_maps(key, fixture_maps) ⇒ Object
-
#initialize(*names) ⇒ ExpectedResultSet
constructor
A new instance of ExpectedResultSet.
- #row_hash(index) ⇒ Object
- #row_hashes ⇒ Object
- #with_row(row_hash) ⇒ Object
Constructor Details
#initialize(*names) ⇒ ExpectedResultSet
Returns a new instance of ExpectedResultSet.
4 5 6 7 |
# File 'lib/expected_result_set.rb', line 4 def initialize(*names) @columns = names.map {|column| column.to_s} @rows = [] end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
2 3 4 |
# File 'lib/expected_result_set.rb', line 2 def columns @columns end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
2 3 4 |
# File 'lib/expected_result_set.rb', line 2 def rows @rows end |
Instance Method Details
#add_fixture(*fixture_map) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/expected_result_set.rb', line 21 def add_fixture( *fixture_map ) row = [] @columns.each do |column| row << get_value_from_maps( column, fixture_map ) #(fixture_map[column.to_sym] or fixture_map[column.to_s]) end rows << row end |
#get_value_from_maps(key, fixture_maps) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/expected_result_set.rb', line 31 def get_value_from_maps( key, fixture_maps) fixture_maps.each do |fixture_map| value = (fixture_map[key.to_sym] or fixture_map[key.to_s]) return value unless value.nil? end return nil end |
#row_hash(index) ⇒ Object
13 14 15 |
# File 'lib/expected_result_set.rb', line 13 def row_hash(index) return to_hash( @rows[index] ) end |
#row_hashes ⇒ Object
17 18 19 |
# File 'lib/expected_result_set.rb', line 17 def row_hashes return rows.collect { |row| to_hash(row) } end |
#with_row(row_hash) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/expected_result_set.rb', line 40 def with_row(row_hash) row = [] row_hash.each do |column, value| column = column.to_s if @columns.include? column row[@columns.index(column)] = value else @columns << column.to_s row << value end end @rows << row self end |