Class: Imis::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/imis/mapper.rb

Constant Summary collapse

FIELD_MAPPING =
{
  vessel_examiner: ['ABC_ASC_Individual_Demog', 'Vol_Vessel_Examiner'],
  mm: ['ABC_ASC_Individual_Demog', 'TotMMS'],
  mm_updated: ['ABC_ASC_Individual_Demog', 'MMS_Updated']
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ Mapper

Returns a new instance of Mapper.



13
14
15
# File 'lib/imis/mapper.rb', line 13

def initialize(api)
  @api = api
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



11
12
13
# File 'lib/imis/mapper.rb', line 11

def api
  @api
end

Instance Method Details

#update(field_name, value) ⇒ Object

Update a member’s data by a single field name Does not require knowing which business object / iMIS-specific field name to use

Only available for previously-mapped fields



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/imis/mapper.rb', line 22

def update(field_name, value)
  if FIELD_MAPPING.key?(field_name.to_sym)
    business_object_name, field = FIELD_MAPPING[field_name.to_sym]
    api.put(business_object_name, { field => value })
  else
    warn(
      "Mapper does not know how to handle field \"#{field_name}\".\n\n" \
      'You can use api.put(business_object_name, { field_name => value })  ' \
      "if you know the business object and iMIS-specific field name.\n\n"
    ) unless ENV['TESTING']

    raise(
      Imis::Error::Mapper,
      "Unrecognized field: \"#{field_name}\". " \
      'Please report what data you are attempting to work with to ITCom leadership.'
    )
  end
end