Class: Address

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(street, city, state, zip) ⇒ Address

Returns a new instance of Address.



4
5
6
# File 'lib/address.rb', line 4

def initialize(street, city, state, zip)
  @street, @city, @state, @zip = street, city, state, zip
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



2
3
4
# File 'lib/address.rb', line 2

def city
  @city
end

#stateObject

Returns the value of attribute state.



2
3
4
# File 'lib/address.rb', line 2

def state
  @state
end

#streetObject

Returns the value of attribute street.



2
3
4
# File 'lib/address.rb', line 2

def street
  @street
end

#zipObject

Returns the value of attribute zip.



2
3
4
# File 'lib/address.rb', line 2

def zip
  @zip
end

Instance Method Details

#to_xml(wax) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/address.rb', line 8

def to_xml(wax)
  # Chaining approach
  #wax.start('address').
  #  child('street', @street).
  #  child('city', @city).
  #  child('state', @state).
  #  child('zip', @zip).
  #  end!

  # Non-chaining approach
  # Put the current object in a local variable
  # so it can be accessed in the block passed to the write method.
  address = self
  wax.write do
    start 'address'
    child 'street', address.street
    child 'city', address.city
    child 'state', address.state
    child 'zip', address.zip
    end!
  end
end