class Posthorn::Address
Attributes
city[RW]
company[RW]
country[RW]
firstname[RW]
lastname[RW]
no[RW]
street[RW]
zip[RW]
Public Class Methods
new(data)
click to toggle source
# File lib/posthorn/address.rb, line 5 def initialize(data) @company = data[:company] @lastname = data[:lastname] @firstname = data[:firstname] if data[:no] @no = data[:no] @street = data[:street] else chunks = data[:street].split(' ') @no = chunks[-1] @street = chunks[0..-2].join(' ') end @city = data[:city] @zip = data[:zip] @country = data[:country].is_a?(String) ? ISO3166::Country.new(data[:country]) : data[:country] end
Public Instance Methods
company?()
click to toggle source
# File lib/posthorn/address.rb, line 23 def company? @company && !@company.blank? && (@company != [@firstname, @lastname].join(' ')) end
to_h()
click to toggle source
# File lib/posthorn/address.rb, line 27 def to_h rtn = { name: {} } if company? rtn[:name][:companyName] = { company: @company } if @firstname && @lastname rtn[:name][:companyName][:personName] = { firstname: @firstname, lastname: @lastname } end else rtn[:name][:personName] = { firstname: @firstname, lastname: @lastname } end rtn[:address] = { street: @street, houseNo: @no, zip: @zip, city: @city, country: @country.alpha3 } rtn end