Sha256: 372164abd8ee98a8420cfffbdacda902e85cf15f42d2a75dc2dfd15d1de7a677

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true
module Roqua
  module Healthy
    module A19
      class AddressParser
        attr_reader :message

        def initialize(message)
          @message = message
        end

        def address_type
          return nil unless record
          record.fetch('PID.11.7')
        end

        def street
          return nil if record.blank? || record.fetch('PID.11.1').blank?
          record.fetch('PID.11.1').fetch('PID.11.1.1')
        end

        def city
          return nil unless record
          record.fetch('PID.11.3')
        end

        def zipcode
          return nil unless record
          record.fetch('PID.11.5')
        end

        def country
          return nil unless record
          record.fetch('PID.11.6')
        end

        def record
          # PID.11.7 address types:
          # M: Mailing
          # P: Permanent
          # H: Home
          # L: Legal address

          @record ||= get_address_of_type(message, 'M') ||
                      get_address_of_type(message, 'P') ||
                      get_address_of_type(message, 'H') ||
                      get_address_of_type(message, 'L')
        end

        private

        def get_address_of_type(message, type)
          message.fetch('PID').fetch('PID.11').find do |record|
            record.fetch('PID.11.7', :unknown_type_of_address_record) == type
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
roqua-healthy-1.5.9 lib/roqua/healthy/a19/address_parser.rb
roqua-healthy-1.5.8 lib/roqua/healthy/a19/address_parser.rb
roqua-healthy-1.5.7 lib/roqua/healthy/a19/address_parser.rb
roqua-healthy-1.5.6 lib/roqua/healthy/a19/address_parser.rb
roqua-healthy-1.5.5 lib/roqua/healthy/a19/address_parser.rb
roqua-healthy-1.5.4 lib/roqua/healthy/a19/address_parser.rb
roqua-healthy-1.5.3 lib/roqua/healthy/a19/address_parser.rb