Class: Remi::Testing::BusinessRules::DataExample
- Inherits:
-
Object
- Object
- Remi::Testing::BusinessRules::DataExample
- Defined in:
- lib/remi/testing/business_rules.rb
Instance Method Summary collapse
-
#column_hash ⇒ Object
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.
-
#initialize(table) ⇒ DataExample
constructor
A new instance of DataExample.
- #parse_formula(value) ⇒ Object
- #to_df(seed_hash, field_symbolizer:) ⇒ Object
Constructor Details
#initialize(table) ⇒ DataExample
Returns a new instance of DataExample.
537 538 539 |
# File 'lib/remi/testing/business_rules.rb', line 537 def initialize(table) @table = table end |
Instance Method Details
#column_hash ⇒ Object
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.
566 567 568 569 570 571 572 573 |
# File 'lib/remi/testing/business_rules.rb', line 566 def column_hash @table.hashes.reduce({}) do |h, row| row.each do |k,v| (h[k.symbolize] ||= []) << parse_formula(v) end h end end |
#parse_formula(value) ⇒ Object
541 542 543 544 545 546 547 548 549 |
# File 'lib/remi/testing/business_rules.rb', line 541 def parse_formula(value) parsed_value = ParseFormula.parse(value) case parsed_value when '\nil' nil else parsed_value end end |
#to_df(seed_hash, field_symbolizer:) ⇒ Object
551 552 553 554 555 556 557 558 559 560 561 562 |
# File 'lib/remi/testing/business_rules.rb', line 551 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)| h[k.symbolize(field_symbolizer)] = parse_formula(v) h end df.add_row(seed_hash.merge(example_row_sym)) end df end |