Class: FieldMapper::Custom::Value

Inherits:
Standard::Value show all
Defined in:
lib/field_mapper/custom/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, field: nil, priority: nil, standard_value: nil) ⇒ Value

Returns a new instance of Value.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/field_mapper/custom/value.rb', line 13

def initialize(
  value,
  field: nil,
  priority: nil,
  standard_value: nil
)
  super value, field: field

  if !standard_value.nil?
    if field.standard_field.nil?
      message = "[#{field.name}] [#{value}] is mapped to a standard but [#{field.name}] is not"
      raise StandardFieldNotFound.new(message)
    end

    raw_standard_value = standard_value
    standard_value = field.standard_field.find_value(standard_value)

    if standard_value.nil?
      message = "[#{field.name}] [#{value}] is mapped, but the standard [#{field.standard_field.name}] doesn't define the value [#{raw_standard_value}]"
      raise StandardValueNotFound.new(message)
    end
  end

  @priority = priority
  @standard_value = standard_value
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



6
7
8
# File 'lib/field_mapper/custom/value.rb', line 6

def field
  @field
end

#priorityObject (readonly)

Returns the value of attribute priority.



6
7
8
# File 'lib/field_mapper/custom/value.rb', line 6

def priority
  @priority
end

#standard_valueObject (readonly)

Returns the value of attribute standard_value.



6
7
8
# File 'lib/field_mapper/custom/value.rb', line 6

def standard_value
  @standard_value
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/field_mapper/custom/value.rb', line 6

def value
  @value
end