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 cantransform.
-
CODE_MAP
- a hash whose keys are all the String codes which the ConsumerView API may return for theattribute 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 theATTRIBUTE_NAME
constant. -
transform_attribute
- transforms the givenvalue
based on theCODE_MAP
, or raises a+AttributeValueUnrecognisedError+ if the value is not foung in the +CODE_MAP+.
Instance Method Summary collapse
Instance Method Details
#attribute_name ⇒ Object
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 |