Sha256: 81273b94c98818fdac9128a18332fb9289e654f3c61a3a9846d8dbcc8ea813f5

Contents?: true

Size: 1.43 KB

Versions: 5

Compression:

Stored size: 1.43 KB

Contents

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

    REQUIRED_KEYS = [
      :first_name,
      :last_name,
      :civil_status,
      :date_of_birth,
      :gender,
      :ac_holder_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::Name::BuildFirstNameField,
        Fields::Name::BuildLastNameField,
        Fields::Name::BuildCivilStatusField,
        Fields::Name::BuildDateOfBirthField,
        Fields::Name::BuildGenderField,
        Fields::Name::BuildAcHolderTypeField,
      )

      result[:transformed_data]
    end

    module Constants
      # tags
      SEGMENT_TAG = "NA03N01"
      FIRST_NAME_TAG = "01"
      LAST_NAME_TAG = "03"
      CIVIL_STATUS_TAG = "05"
      DATE_OF_BIRTH_TAG = "06"
      GENDER_TAG = "07"
      AC_HOLDER_TYPE_TAG = "12"

      # civil status constants
      SINGLE = "S"
      MARRIED = "M"
      DIVORCED = "D"
      WIDOWED = "W"
      CIVIL_STATUS_UNKNOWN = "U"

      # gender constants
      FEMALE = "1"
      MALE = "2"
      GENDER_UNKNOWN = "3"

      # a/c holder type constants
      HI = "HI"
      HPI = "HPI"
      HJ = "HJ"
      G = "G"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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