Class: Cucumber::Model::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/cucumber-0.1.15/lib/cucumber/model/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Table

Creates a new table. The raw argument should be an array of arrays



8
9
10
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/model/table.rb', line 8

def initialize(raw)
  @raw = raw
end

Instance Attribute Details

#rawObject

Returns the value of attribute raw.



4
5
6
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/model/table.rb', line 4

def raw
  @raw
end

Instance Method Details

#hashesObject

Turn the table into an array of Hash where each Hash has keys corresponding to the table header (first line) and the values are the individual row cells.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gems/cucumber-0.1.15/lib/cucumber/model/table.rb', line 15

def hashes
  header = @raw[0]
  @raw[1..-1].map do |row|
    h = {}
    row.each_with_index do |v,n|
      key = header[n]
      h[key] = v
    end
    h
  end
end