Class: Remi::Testing::BusinessRules::DataExample

Inherits:
Object
  • Object
show all
Defined in:
lib/remi/testing/business_rules.rb

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ DataExample

Returns a new instance of DataExample.



520
521
522
# File 'lib/remi/testing/business_rules.rb', line 520

def initialize(table)
  @table = table
end

Instance Method Details

#column_hashObject

Public: Converts a Cucumber::Ast::Table to a hash where the keys are the table columns and the values are an array for the value of column for each row.



546
547
548
549
550
551
552
553
# File 'lib/remi/testing/business_rules.rb', line 546

def column_hash
  @table.hashes.reduce({}) do |h, row|
    row.each do |k,v|
      (h[k.symbolize] ||= []) << v
    end
    h
  end
end

#to_df(seed_hash, field_symbolizer:) ⇒ Object



524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/remi/testing/business_rules.rb', line 524

def to_df(seed_hash, field_symbolizer:)
  table_headers = @table.headers.map { |h| h.symbolize(field_symbolizer) }
  df = Daru::DataFrame.new([], order: seed_hash.keys | table_headers)
  @table.hashes.each do |example_row|
    example_row_sym = example_row.reduce({}) do |h, (k,v)|
      formula_value = ParseFormula.parse(v)
      value = case formula_value
        when '\nil'
          nil
        else
          formula_value
        end
      h[k.symbolize(field_symbolizer)] = value
      h
    end
    df.add_row(seed_hash.merge(example_row_sym))
  end
  df
end