class Cucumber::Salad::Table

Attributes

table[RW]

Public Class Methods

Array(table) click to toggle source
# File lib/cucumber/salad/table.rb, line 10
def Array(table)
  new(table).to_a
end
Hash(table) click to toggle source
# File lib/cucumber/salad/table.rb, line 14
def Hash(table)
  new(table).to_h
end
map(name, options = {}, &block) click to toggle source
# File lib/cucumber/salad/table.rb, line 18
def map(name, options = {}, &block)
  case name
  when :*
    set_default_mapping options, &block
  else
    set_mapping name, options, &block
  end
end
mappings() click to toggle source
# File lib/cucumber/salad/table.rb, line 27
def mappings
  @mappings ||= Hash.
   new { |h, k| h[k] = Mapping.new }.
   merge(with_parent_mappings)
end
new(table) click to toggle source
# File lib/cucumber/salad/table.rb, line 75
def initialize(table)
  self.table = table
end
skip(name) click to toggle source
# File lib/cucumber/salad/table.rb, line 33
def skip(name)
  case name
  when :*
    set_default_mapping VoidMapping
  else
    raise ArgumentError, "can't convert #{name.inspect} to name"
  end
end

Private Class Methods

set_default_mapping(options, &block) click to toggle source
# File lib/cucumber/salad/table.rb, line 44
def set_default_mapping(options, &block)
  case options
  when Hash
    @mappings = Hash.
     new { |h, k|
      h[k] = Mapping.new(key_transformer:   options[:to],
                         value_transformer: block) }.
     merge(mappings)
  when Class
    @mappings = Hash.new { |h, k| h[k] = options.new }.merge(mappings)
  else
    raise ArgumentError, "can't convert #{options.inspect} to mapping"
  end
end
set_mapping(name, options, &block) click to toggle source
# File lib/cucumber/salad/table.rb, line 59
def set_mapping(name, options, &block)
  mappings[name] = Mapping.
   new(key: options[:to], value_transformer: block)
end
with_parent_mappings() click to toggle source
# File lib/cucumber/salad/table.rb, line 64
def with_parent_mappings
  if superclass.respond_to?(:mappings)
    superclass.send(:mappings).dup
  else
    {}
  end
end

Public Instance Methods

each(&block) click to toggle source
# File lib/cucumber/salad/table.rb, line 79
def each(&block)
  rows.each(&block)
end
rows() click to toggle source
# File lib/cucumber/salad/table.rb, line 83
def rows
  @rows ||= table.hashes.map { |h| new_row(h) }
end
Also aliased as: to_a
single_row() click to toggle source
# File lib/cucumber/salad/table.rb, line 87
def single_row
  @single_row ||= new_row(table.rows_hash)
end
Also aliased as: to_h
to_a()
Alias for: rows
to_h()
Alias for: single_row

Private Instance Methods

mapping_for(header) click to toggle source
# File lib/cucumber/salad/table.rb, line 104
def mapping_for(header)
  mappings[header]
end
new_row(hash) click to toggle source
# File lib/cucumber/salad/table.rb, line 98
def new_row(hash)
  hash.each_with_object({}) { |(k, v), h|
    mapping_for(k).set(self, h, k, CellText.new(v))
  }
end