Class: CSVJoin::DataRow

Inherits:
CSV::Row
  • Object
show all
Defined in:
lib/data_row.rb

Overview

CSV::Row with specified important columns to compare

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



8
9
10
# File 'lib/data_row.rb', line 8

def columns
  @columns
end

#sideObject

Returns the value of attribute side.



9
10
11
# File 'lib/data_row.rb', line 9

def side
  @side
end

#weightsObject

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

Returns:

  • (Boolean)


17
18
19
# File 'lib/data_row.rb', line 17

def eql?(other)
  self == other
end

#hashObject



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

#inspectObject



13
14
15
# File 'lib/data_row.rb', line 13

def inspect
  "#{side}:#{super}"
end