Sha256: 0bc29d912bcf57aba6fbf43ea293c3f78d0a8a3add99b9ebcc450ea438957266

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

module Loqate
  # A result from the address retrieve service.
  class DetailedAddress
    # For the first version, this will be a flat structure, exactly as it is defined in Loqate's API.
    # But this many attributes is too much for a single object to hold.
    #
    # @api private
    #
    ATTRIBUTES = %i[
      admin_area_code
      admin_area_name
      barcode
      block
      building_name
      building_number
      city
      company
      country_iso2
      country_iso3
      country_iso_number
      country_name
      data_level
      department
      district
      domestic_id
      field1
      field2
      field3
      field4
      field5
      field6
      field7
      field8
      field9
      field10
      field11
      field12
      field13
      field14
      field15
      field16
      field17
      field18
      field19
      field20
      id
      label
      language
      language_alternatives
      line1
      line2
      line3
      line4
      line5
      neighbourhood
      po_box_number
      postal_code
      province
      province_code
      province_name
      secondary_street
      sorting_number1
      sorting_number2
      street
      sub_building
      type
    ].freeze

    ATTRIBUTES.each do |attribute|
      attr_reader attribute
    end

    def initialize(options = {})
      options.each_pair do |key, value|
        instance_variable_set("@#{key}", value) if ATTRIBUTES.include?(key)
      end
    end

    def ==(other)
      other.is_a?(DetailedAddress) && id == other.id
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
loqate-0.6.0 lib/loqate/detailed_address.rb
loqate-0.5.0 lib/loqate/detailed_address.rb
loqate-0.4.0 lib/loqate/detailed_address.rb
loqate-0.3.0 lib/loqate/detailed_address.rb
loqate-0.2.0 lib/loqate/detailed_address.rb