Class: Remi::BusinessRules::DataFieldCollection
- Inherits:
-
Object
- Object
- Remi::BusinessRules::DataFieldCollection
- Includes:
- Enumerable
- Defined in:
- lib/remi/cucumber/business_rules.rb
Instance Method Summary collapse
- #[](field_name) ⇒ Object
- #add_field(subject, field_name) ⇒ Object
- #each(&block) ⇒ Object
- #field_names ⇒ Object
-
#initialize ⇒ DataFieldCollection
constructor
A new instance of DataFieldCollection.
- #keys ⇒ Object
- #names ⇒ Object
- #only ⇒ Object
-
#values ⇒ Object
All values get tested as strings.
Constructor Details
#initialize ⇒ DataFieldCollection
Returns a new instance of DataFieldCollection.
420 421 422 |
# File 'lib/remi/cucumber/business_rules.rb', line 420 def initialize @fields = {} end |
Instance Method Details
#[](field_name) ⇒ Object
424 425 426 |
# File 'lib/remi/cucumber/business_rules.rb', line 424 def [](field_name) @fields[field_name] end |
#add_field(subject, field_name) ⇒ Object
444 445 446 447 |
# File 'lib/remi/cucumber/business_rules.rb', line 444 def add_field(subject, field_name) raise "Attempting to add a field with the same name but different subject - #{subject.name}: #{field_name}" if @fields.include?(field_name) && @fields[field_name].subject.name != subject.name @fields[field_name] = DataField.new(subject, field_name) unless @fields.include? field_name end |
#each(&block) ⇒ Object
428 429 430 |
# File 'lib/remi/cucumber/business_rules.rb', line 428 def each(&block) @fields.each(&block) end |
#field_names ⇒ Object
440 441 442 |
# File 'lib/remi/cucumber/business_rules.rb', line 440 def field_names @fields.values.map(&:field_name) end |
#keys ⇒ Object
432 433 434 |
# File 'lib/remi/cucumber/business_rules.rb', line 432 def keys @fields.keys end |
#names ⇒ Object
436 437 438 |
# File 'lib/remi/cucumber/business_rules.rb', line 436 def names @fields.values.map(&:name) end |
#only ⇒ Object
449 450 451 452 |
# File 'lib/remi/cucumber/business_rules.rb', line 449 def only raise "Multiple subject fields defined: #{keys}" if @fields.size > 1 @fields.values.first end |
#values ⇒ Object
All values get tested as strings
455 456 457 |
# File 'lib/remi/cucumber/business_rules.rb', line 455 def values @fields.map { |field_name, field| field.values.map(&:to_s) }.transpose end |