Class: Remi::Testing::BusinessRules::DataField
- Inherits:
-
Object
- Object
- Remi::Testing::BusinessRules::DataField
- Defined in:
- lib/remi/testing/business_rules.rb
Instance Attribute Summary collapse
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #full_name ⇒ Object
-
#initialize(subject, name) ⇒ DataField
constructor
A new instance of DataField.
- #metadata ⇒ Object
- #value ⇒ Object
- #value=(arg) ⇒ Object
- #values ⇒ Object
- #vector ⇒ Object
Constructor Details
#initialize(subject, name) ⇒ DataField
Returns a new instance of DataField.
450 451 452 453 454 |
# File 'lib/remi/testing/business_rules.rb', line 450 def initialize(subject, name) @subject = subject @name = name @field_name = name.symbolize(subject.data_subject.field_symbolizer) end |
Instance Attribute Details
#field_name ⇒ Object (readonly)
Returns the value of attribute field_name.
457 458 459 |
# File 'lib/remi/testing/business_rules.rb', line 457 def field_name @field_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
456 457 458 |
# File 'lib/remi/testing/business_rules.rb', line 456 def name @name end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
458 459 460 |
# File 'lib/remi/testing/business_rules.rb', line 458 def subject @subject end |
Instance Method Details
#full_name ⇒ Object
460 461 462 |
# File 'lib/remi/testing/business_rules.rb', line 460 def full_name "#{@subject.name}: #{@name}" end |
#metadata ⇒ Object
464 465 466 |
# File 'lib/remi/testing/business_rules.rb', line 464 def @subject.data_subject.fields[@field_name] end |
#value ⇒ Object
472 473 474 475 476 |
# File 'lib/remi/testing/business_rules.rb', line 472 def value v = vector.to_a.uniq raise "Multiple unique values found in subject data for field #{@field_name}" if v.size > 1 v.first end |
#value=(arg) ⇒ Object
482 483 484 485 486 487 488 489 490 |
# File 'lib/remi/testing/business_rules.rb', line 482 def value=(arg) typed_arg = if [:type] == :json JSON.parse(arg) else arg end vector.recode! { |_v| typed_arg } end |
#values ⇒ Object
478 479 480 |
# File 'lib/remi/testing/business_rules.rb', line 478 def values vector.to_a.map(&:to_s) end |
#vector ⇒ Object
468 469 470 |
# File 'lib/remi/testing/business_rules.rb', line 468 def vector @subject.data_subject.df[@field_name] end |