Sha256: 6cee14bd484e015bcb5f2831a3f4bc946e6ed2a6821cc28c08523aa28c99c918

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require_relative 'base'

module BrregGrunndata
  module Types
    class Address < Base
      attribute :street_parts,        Types::Array.member(Types::String).default([])
      attribute :postal_code,         Types::String
      attribute :postal_area,         Types::String
      attribute :municipality_number, Types::String
      attribute :municipality,        Types::String
      attribute :country_code,        Types::String
      attribute :country,             Types::String

      # Returns this address' street
      #
      # Brreg returns street as three parts. You find them in #street_parts.
      # If you just one a string representing the street this is your method.
      # It joins the parts by given separator defaulting to ', '
      #
      # @return String
      def street(separator = ', ')
        street_parts.join separator
      end

      def to_hash
        super.tap do |hash|
          hash[:street] = street
        end
      end

      alias to_h to_hash
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brreg_grunndata-0.1.7 lib/brreg_grunndata/types/address.rb
brreg_grunndata-0.1.6 lib/brreg_grunndata/types/address.rb
brreg_grunndata-0.1.5 lib/brreg_grunndata/types/address.rb
brreg_grunndata-0.1.4 lib/brreg_grunndata/types/address.rb