Sha256: 385d66924d8bf505d9ec86252558f1688d93109fc0e990c5691cc8c7b430b788

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

module Tufy
  class BuildContactNumberSegment < BuildSegment
    expects :raw_data
    promises :transformed_data

    REQUIRED_KEYS = [
      :contact_number,
      :contact_number_format,
      :contact_number_type,
    ]

    executed do |ctx|
      validate_presence_of_required_keys(ctx.raw_data, REQUIRED_KEYS)
      ctx.transformed_data = transform(ctx).upcase
    end

    private

    def self.transform(ctx)
      ctx[:segment_tag] = Constants::SEGMENT_TAG

      result = with(ctx).reduce(
        Fields::BuildSegmentTagField,
        Fields::ContactNumber::BuildContactNumberField,
        Fields::ContactNumber::BuildContactNumberFormatField,
        Fields::ContactNumber::BuildContactNumberTypeField,
      )

      result[:transformed_data]
    end

    module Constants
      # tags
      SEGMENT_TAG = "PH03P01"
      CONTACT_NUMBER_TAG = "03"
      CONTACT_NUMBER_FORMAT_TAG = "05"
      CONTACT_NUMBER_TYPE_TAG = "06"

      # contact number format constants
      FREE_FORMAT = "F"
      STRUCTURED_FORMAT = "S"

      RESIDENTIAL = "R"
      OFFICE = "O"
      MOBILE = "M"
      CORRESPONDENCE_OR_CONTACT = "C"
      UNKNOWN = "U"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tufy-0.0.13 lib/tufy/build_contact_number_segment.rb
tufy-0.0.12 lib/tufy/build_contact_number_segment.rb
tufy-0.0.11 lib/tufy/build_contact_number_segment.rb
tufy-0.0.10 lib/tufy/build_contact_number_segment.rb
tufy-0.0.9 lib/tufy/build_contact_number_segment.rb