class ActiveCucumber::Cucumparer

Public Class Methods

new(database_content, cucumber_table, context) click to toggle source
# File lib/active_cucumber/cucumparer.rb, line 5
def initialize database_content, cucumber_table, context
  @database_content = database_content
  @cucumber_table = cucumber_table
  @context = context
end

Public Instance Methods

to_horizontal_table() click to toggle source

Returns all entries in the database as a horizontal Mortadella table

# File lib/active_cucumber/cucumparer.rb, line 12
def to_horizontal_table
  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) click to toggle source

Returns the given object as a vertical Mortadella table

# File lib/active_cucumber/cucumparer.rb, line 25
def to_vertical_table object
  mortadella = Mortadella::Vertical.new
  cucumberator = cucumberator_for object
  @cucumber_table.rows_hash.each do |key, _|
    mortadella[key] = cucumberator.value_for key
  end
  mortadella.table
end

Private Instance Methods

cucumberator_class(object) click to toggle source

Returns the Cucumberator subclass to be used by this Cucumparer instance

# File lib/active_cucumber/cucumparer.rb, line 37
def cucumberator_class object
  cucumberator_class_name(object).constantize
rescue NameError
  Cucumberator
end
cucumberator_class_name(object) click to toggle source

Returns the name of the Cucumberator subclass to be used by this Cucumparer instance.

# File lib/active_cucumber/cucumparer.rb, line 44
def cucumberator_class_name object
  "#{object.class.name}Cucumberator"
end
cucumberator_for(object) click to toggle source

Returns the Cucumberator object for the given ActiveRecord instance

# File lib/active_cucumber/cucumparer.rb, line 49
def cucumberator_for object
  cucumberator_class(object).new object, @context
end