Class: Strikeiron::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/strikeiron/address.rb

Overview

An Address stores information of a physical location for both the seller and customer.

Attributes

  • street_address - The full street address for the seller/customer. Example: 123 Sixth Avenue.

  • city - The city of the address.

  • state - The two letter abbreviation for the state. Example: NY.

  • zip_code - The postal/ZIP code of the address.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_values = {}) ⇒ Address

Creates an Address with the supplied attributes.



15
16
17
18
19
20
21
# File 'lib/strikeiron/address.rb', line 15

def initialize(default_values = {})
  safe_keys = %w(street_address city state zip_code)
  # Only permit the keys defined in safe_keys
  default_values.reject! { |key, value| !safe_keys.include?(key.to_s) }

  default_values.each { |key, value| self.send "#{key}=", value }
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



12
13
14
# File 'lib/strikeiron/address.rb', line 12

def city
  @city
end

#stateObject

Returns the value of attribute state.



12
13
14
# File 'lib/strikeiron/address.rb', line 12

def state
  @state
end

#street_addressObject

Returns the value of attribute street_address.



12
13
14
# File 'lib/strikeiron/address.rb', line 12

def street_address
  @street_address
end

#zip_codeObject

Returns the value of attribute zip_code.



12
13
14
# File 'lib/strikeiron/address.rb', line 12

def zip_code
  @zip_code
end

Class Method Details

.from_soap(hash = {}) ⇒ Object

Convert the object from a SOAP response to an Address object



35
36
37
38
39
40
41
42
43
# File 'lib/strikeiron/address.rb', line 35

def from_soap(hash = {})
  default_values = {
    :street_address => hash['StreetAddress'],
    :city           => hash['City'],
    :state          => hash['State'],
    :zip_code       => hash['ZIPCode']
  }
  new(default_values)
end

Instance Method Details

#to_soapObject

Convert the object to a Hash for SOAP



24
25
26
27
28
29
30
31
# File 'lib/strikeiron/address.rb', line 24

def to_soap
  {
    'StreetAddress' => street_address,
    'City'          => city,
    'State'         => state,
    'ZIPCode'       => zip_code
  }
end