Class: CSVJoin::DataRow
- Inherits:
-
CSV::Row
- Object
- CSV::Row
- CSVJoin::DataRow
- Defined in:
- lib/data_row.rb
Overview
CSV::Row with specified important columns to compare
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#side ⇒ Object
Returns the value of attribute side.
-
#weights ⇒ Object
Returns the value of attribute weights.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Returns
true
if this row contains the same headers and fields in the same order asother
. - #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #inspect ⇒ Object
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
8 9 10 |
# File 'lib/data_row.rb', line 8 def columns @columns end |
#side ⇒ Object
Returns the value of attribute side.
9 10 11 |
# File 'lib/data_row.rb', line 9 def side @side end |
#weights ⇒ Object
Returns the value of attribute weights.
8 9 10 |
# File 'lib/data_row.rb', line 8 def weights @weights end |
Instance Method Details
#==(other) ⇒ Object
Returns true
if this row contains the same headers and fields in the same order as other
.
35 36 37 38 39 40 41 42 |
# File 'lib/data_row.rb', line 35 def ==(other) @columns.each_with_index do |from, index| to = other.columns[index] # warn "something wrong" if self[from].nil? || other[to].nil? return false unless self[from].eql? other[to] end return true end |
#eql?(other) ⇒ Boolean
17 18 19 |
# File 'lib/data_row.rb', line 17 def eql?(other) self == other end |
#hash ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/data_row.rb', line 21 def hash res = [] @weights.each_with_index do |_weight, index| field = @columns[index] warn("something wrong, #{inspect}, side #{side.inspect}, f'#{field}'==nil") if self[field].nil? res << self[field] end return res.hash end |
#inspect ⇒ Object
13 14 15 |
# File 'lib/data_row.rb', line 13 def inspect "#{side}:#{super}" end |