Class: Blackbird::Retoure::SimpleAddress

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/blackbird/retoure/simple_address.rb

Overview

Public: Representation of DHLs SimpleClass object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ SimpleAddress

Returns a new instance of SimpleAddress.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/blackbird/retoure/simple_address.rb', line 22

def initialize(args = {})
  @name1 = args[:name1]
  @name2 = args[:name2]
  @name3 = args[:name3]
  @street_name = args[:street_name]
  @house_number = args[:house_number]
  @post_code = args[:post_code]
  @city = args[:city]

  self.country = args[:country] if args[:country]
end

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city.



7
8
9
# File 'lib/blackbird/retoure/simple_address.rb', line 7

def city
  @city
end

#countryObject

Returns the value of attribute country.



7
8
9
# File 'lib/blackbird/retoure/simple_address.rb', line 7

def country
  @country
end

#house_numberObject (readonly)

Returns the value of attribute house_number.



7
8
9
# File 'lib/blackbird/retoure/simple_address.rb', line 7

def house_number
  @house_number
end

#name1Object (readonly)

Returns the value of attribute name1.



7
8
9
# File 'lib/blackbird/retoure/simple_address.rb', line 7

def name1
  @name1
end

#name2Object (readonly)

Returns the value of attribute name2.



7
8
9
# File 'lib/blackbird/retoure/simple_address.rb', line 7

def name2
  @name2
end

#name3Object (readonly)

Returns the value of attribute name3.



7
8
9
# File 'lib/blackbird/retoure/simple_address.rb', line 7

def name3
  @name3
end

#post_codeObject (readonly)

Returns the value of attribute post_code.



7
8
9
# File 'lib/blackbird/retoure/simple_address.rb', line 7

def post_code
  @post_code
end

#street_nameObject (readonly)

Returns the value of attribute street_name.



7
8
9
# File 'lib/blackbird/retoure/simple_address.rb', line 7

def street_name
  @street_name
end

Instance Method Details

#to_jsonObject

Public: Create a JSON payload of this class.

Returns a String representing the JSON payload.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/blackbird/retoure/simple_address.rb', line 49

def to_json
  json_payload = {
    name1: @name1, streetName: @street_name, houseNumber: @house_number, postCode: @post_code, city: @city
  }

  json_payload[:name2] = @name2 if @name2.present?
  json_payload[:name3] = @name3 if @name3.present?
  json_payload[:country] = JSON.parse(@country.to_json) if @country.present?

  json_payload.to_json
end