Class: ActiveCucumber::Cucumparer

Inherits:
Object
  • Object
show all
Defined in:
lib/active_cucumber/cucumparer.rb

Overview

provides Mortadella instances of the given database content

Instance Method Summary collapse

Constructor Details

#initialize(database_content, cucumber_table, context) ⇒ Cucumparer

Returns a new instance of Cucumparer.



6
7
8
9
10
# File 'lib/active_cucumber/cucumparer.rb', line 6

def initialize(database_content, cucumber_table, context)
  @database_content = database_content
  @cucumber_table = cucumber_table
  @context = context
end

Instance Method Details

#to_horizontal_tableObject

Returns all entries in the database as a horizontal Mortadella table

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/active_cucumber/cucumparer.rb', line 13

def to_horizontal_table
  raise ArgumentError, "No headers provided in Cucumber table" if @cucumber_table.headers.empty?

  mortadella = Mortadella::Horizontal.new headers: @cucumber_table.headers
  @database_content = @database_content.all if @database_content.respond_to? :all
  @database_content.each do |record|
    cucumberator = cucumberator_for record
    mortadella << @cucumber_table.headers.map do |header|
      cucumberator.value_for header
    end
  end
  mortadella.table
end

#to_vertical_table(object) ⇒ Object

Returns the given object as a vertical Mortadella table



28
29
30
31
32
33
34
35
# File 'lib/active_cucumber/cucumparer.rb', line 28

def to_vertical_table(object)
  mortadella = Mortadella::Vertical.new
  cucumberator = cucumberator_for object
  @cucumber_table.rows_hash.each_key do |key|
    mortadella[key] = cucumberator.value_for key
  end
  mortadella.table
end