Sha256: 2811d9b970b985776a0afd14173baa0c04ae8efc2c97c91dd0f37ce8c0b05a79

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

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

    REQUIRED_KEYS = [
      :id_number,
      :id_type,
    ]

    executed do |ctx|
      # ID Segment is not required.
      # If ID type passed here does
      # not exist, do not proceed.
      # TODO: Testing
      validate_presence_of_required_keys(ctx.raw_data, REQUIRED_KEYS)
      if id_type_exists?(ctx.raw_data[:id_type])
        ctx.transformed_data = ctx.transformed_data + transform(ctx).upcase
      end
    end

    private

    def self.transform(ctx)
      raw_data = ctx[:raw_data]

      Constants::SEGMENT_TAG + # Segment Tag (Required)
        Constants::ID_NUMBER_TAG +
          FormatStrings::F2TS % remove_special_characters(raw_data[:id_number]).size +
            remove_special_characters(raw_data[:id_number]) + # ID Number (Required)
        Constants::ID_TYPE_TAG +
          FormatStrings::F2TS % raw_data[:id_type].size +
            raw_data[:id_type] # ID Type (Required)
    end

    def self.id_type_exists?(id_type)
      Constants::ID_TYPES.include?(id_type)
    end

    module Constants
      # tags
      SEGMENT_TAG = "ID03I01"
      ID_NUMBER_TAG = "01"
      ID_TYPE_TAG = "02"

      # id type constants
      SSS = "SSS"
      PP = "PP"
      TIN = "TIN"
      DL = "DL"
      GSIS = "GSIS"
      UMID = "UMID"

      ID_TYPES = [SSS, PP, TIN, DL, GSIS, UMID]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tufy-0.0.6 lib/tufy/build_id_segment.rb
tufy-0.0.5 lib/tufy/build_id_segment.rb
tufy-0.0.4 lib/tufy/build_id_segment.rb
tufy-0.0.3 lib/tufy/build_id_segment.rb
tufy-0.0.2 lib/tufy/build_id_segment.rb
tufy-0.0.1 lib/tufy/build_id_segment.rb