module BrregGrunndata::Types::Factory
Public Instance Methods
__address(h)
click to toggle source
As of writing, keys for postal and business address are the same, so the are both initialized here
# File lib/brreg_grunndata/types/factories.rb, line 86 def __address(h) return nil if h.nil? Address.new( street_parts: [h[:adresse1], h[:adresse2], h[:adresse3]].compact, postal_code: h[:postnr], postal_area: h[:poststed], municipality_number: h[:kommunenummer], municipality: h[:kommune], country_code: h[:landkode], country: h[:land] ) end
additional_information(lines)
click to toggle source
# File lib/brreg_grunndata/types/factories.rb, line 72 def additional_information(lines) lines = [lines].compact.flatten lines.map do |line| AdditionalInformation.new( status_code: line[:@statuskode], description: line[:tekst_linje], registered_date: line[:@registrerings_dato] ) end end
business_address(hash)
click to toggle source
Creates a address for given Hash
@return BrregGrunndata::Types::Address
# File lib/brreg_grunndata/types/factories.rb, line 49 def business_address(hash) __address hash end
organization(h)
click to toggle source
Creates an organization from given hash
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
@return BrregGrunndata::Types::Organization
# File lib/brreg_grunndata/types/factories.rb, line 19 def organization(h) name = h.fetch :navn, {} name = [ name[:navn1], name[:navn2], name[:navn3], name[:navn4], name[:navn5] ].compact.join ' ' Organization.new( orgnr: h.fetch(:organisasjonsnummer), organizational_form: organizational_form(h[:organisasjonsform]), name: name.length > 0 ? name : nil, telephone_number: h[:telefonnummer], telefax_number: h[:telefaksnummer], mobile_number: h[:mobiltelefonnummer], email: h[:epostadresse], web_page: h[:hjemmesideadresse], business_address: business_address(h[:forretnings_adresse]), postal_address: postal_address(h[:post_adresse]), additional_information: additional_information(h.dig(:saerlige_opplysninger, :status)) ) end
organizational_form(h)
click to toggle source
Creates a organizational form for given Hash
@return BrregGrunndata::Types::OrganizationalForm
# File lib/brreg_grunndata/types/factories.rb, line 63 def organizational_form(h) return nil if h.nil? OrganizationalForm.new( name: h[:orgform], description: h[:orgform_beskrivelse] ) end
postal_address(hash)
click to toggle source
Creates a address for given Hash
@return BrregGrunndata::Types::Address
# File lib/brreg_grunndata/types/factories.rb, line 56 def postal_address(hash) __address hash end