Class: Cards::TabularParser::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/cards/tabular_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(header, row) ⇒ Row

Returns a new instance of Row.



59
60
61
# File 'lib/cards/tabular_parser.rb', line 59

def initialize(header, row)
  @header, @row = header, row
end

Instance Method Details

#[](key) ⇒ Object



63
64
65
66
# File 'lib/cards/tabular_parser.rb', line 63

def [](key)
  index = @header[key] || raise("can't find column header #{key.inspect} in #{@header.inspect}")
  @row[index]
end

#to_hObject



68
69
70
71
72
73
74
75
# File 'lib/cards/tabular_parser.rb', line 68

def to_h
  h = {}
  @header.each_key do |column_header|
    val = @row[@header[column_header]]
    h[column_header] = val unless val.blank?
  end
  h
end