Class: SeparatedValues::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/separated_values/row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values, options = DEFAULT_OPTIONS) ⇒ Row

Returns a new instance of Row.



5
6
7
8
# File 'lib/separated_values/row.rb', line 5

def initialize(values, options = DEFAULT_OPTIONS)
  @values = values
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/separated_values/row.rb', line 3

def options
  @options
end

Instance Method Details

#[](index) ⇒ Object



10
11
12
# File 'lib/separated_values/row.rb', line 10

def [](index)
  @values[index]
end

#to_h(schema = options[:schema]) ⇒ Object



14
15
16
17
18
# File 'lib/separated_values/row.rb', line 14

def to_h(schema = options[:schema])
  schema.each_with_object({}).with_index do |(key, hash), i|
    hash[key] = @values[i]
  end
end