Module: ExperianConsumerView::Transformers::Attributes::Base

Included in:
Match, PostcodeMosaicUk7Group, PostcodeMosaicUk7Type
Defined in:
lib/experian_consumer_view/transformers/attributes/base.rb

Overview

Base mpdule for Attribute Transformers. Mixin to Attribute Transformer classes with extend ExperianConsumerView::Transformers::Attributes::Base.

Expects the class to provide two constants:

  • ATTRIBUTE_NAME - the name of the attribute, as returned by the ConsumerView API, which the class can

    transform.
    
  • CODE_MAP - a hash whose keys are all the String codes which the ConsumerView API may return for the

    attribute in question, and whose values are the what the attribute should be mapped to when the matching
    code is returned.
    

This module will then provide two class-level methods:

  • attribute_name - simply returns the value of the ATTRIBUTE_NAME constant.

  • transform_attribute - transforms the given value based on the CODE_MAP, or raises a

    +AttributeValueUnrecognisedError+ if the value is not foung in the +CODE_MAP+.
    

Instance Method Summary collapse

Instance Method Details

#attribute_nameObject



21
22
23
# File 'lib/experian_consumer_view/transformers/attributes/base.rb', line 21

def attribute_name
  self::ATTRIBUTE_NAME
end

#transform_attribute(value) ⇒ Object



25
26
27
28
29
# File 'lib/experian_consumer_view/transformers/attributes/base.rb', line 25

def transform_attribute(value)
  return self::CODE_MAP[value] if self::CODE_MAP[value]

  raise ExperianConsumerView::Errors::AttributeValueUnrecognisedError
end