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.
394 395 396 |
# File 'lib/remi/cucumber/business_rules.rb', line 394 def initialize @fields = {} end |
Instance Method Details
#[](field_name) ⇒ Object
398 399 400 |
# File 'lib/remi/cucumber/business_rules.rb', line 398 def [](field_name) @fields[field_name] end |
#add_field(subject, field_name) ⇒ Object
418 419 420 421 |
# File 'lib/remi/cucumber/business_rules.rb', line 418 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
402 403 404 |
# File 'lib/remi/cucumber/business_rules.rb', line 402 def each(&block) @fields.each(&block) end |
#field_names ⇒ Object
414 415 416 |
# File 'lib/remi/cucumber/business_rules.rb', line 414 def field_names @fields.values.map(&:field_name) end |
#keys ⇒ Object
406 407 408 |
# File 'lib/remi/cucumber/business_rules.rb', line 406 def keys @fields.keys end |
#names ⇒ Object
410 411 412 |
# File 'lib/remi/cucumber/business_rules.rb', line 410 def names @fields.values.map(&:name) end |
#only ⇒ Object
423 424 425 426 |
# File 'lib/remi/cucumber/business_rules.rb', line 423 def only raise "Multiple subject fields defined: #{keys}" if @fields.size > 1 @fields.values.first end |
#values ⇒ Object
All values get tested as strings
429 430 431 |
# File 'lib/remi/cucumber/business_rules.rb', line 429 def values @fields.map { |field_name, field| field.values.map(&:to_s) }.transpose end |