Sha256: 6f2c35993130b4326167433f21f0cc397d33f90b27f2410bf251acfeb01ae9e1

Contents?: true

Size: 1.28 KB

Versions: 17

Compression:

Stored size: 1.28 KB

Contents

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

        def initialize(message)
          @message = message
        end

        def firstname
          return unless names[:nick]
          names[:nick].fetch('PID.5.2')
        end

        def initials
          "#{names[:legal].fetch('PID.5.2')} #{names[:legal].fetch('PID.5.3')}".strip
        end

        def lastname
          prefix   = names[:legal].fetch('PID.5.1').fetch('PID.5.1.2')
          lastname = names[:legal].fetch('PID.5.1').fetch('PID.5.1.3')
          "#{prefix} #{lastname}".strip
        end

        def display_name
          return unless names[:display]
          names[:display].fetch('PID.5.1')
        end

        def nickname
          firstname
        end

        private

        def names
          names = {}
          message.fetch('PID').fetch('PID.5').each do |record|
            case record.fetch('PID.5.7', :unknown_type_of_name_record)
            when 'L'
              names[:legal] = record
            when 'D'
              names[:display] = record
            when 'N'
              names[:nick] = record
              # else ignore record
            end
          end
          names
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
roqua-healthy-1.6.0 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.13 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.12 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.11 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.10 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.9 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.8 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.7 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.6 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.5 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.4 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.3 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.2 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.1 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.5.0 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.4.3 lib/roqua/healthy/a19/name_parser.rb
roqua-healthy-1.4.2 lib/roqua/healthy/a19/name_parser.rb