class TSV::Row
Attributes
data[R]
header[R]
Public Class Methods
new(data, header)
click to toggle source
# File lib/tsv/row.rb, line 27 def initialize(data, header) @data = data @header = header raise InputError.new("Row has #{@data.length} columns, but #{@header.length} columns expected") if @data.length != @header.length end
Public Instance Methods
==(other)
click to toggle source
# File lib/tsv/row.rb, line 39 def ==(other) other.is_a?(self.class) and header == other.header and data == other.data end
[](key)
click to toggle source
# File lib/tsv/row.rb, line 13 def [](key) if key.is_a? ::String raise UnknownKey unless header.include?(key) data[header.index(key)] elsif key.is_a? ::Numeric raise UnknownKey if data[key].nil? data[key] else raise InvalidKey.new end end
[]=(key, value)
click to toggle source
# File lib/tsv/row.rb, line 9 def []=(key, value) raise TSV::ReadOnly.new('TSV data is read only. Export data to modify it.') end
with_header()
click to toggle source
# File lib/tsv/row.rb, line 34 def with_header Hash[header.zip(data)] end
Also aliased as: to_h