Class: Postie::Locality

Inherits:
Object
  • Object
show all
Defined in:
lib/postie/locality.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Locality

Returns a new instance of Locality.



8
9
10
11
12
13
# File 'lib/postie/locality.rb', line 8

def initialize(hash)
  @suburb   = hash[:suburb]
  @postcode = hash[:postcode]
  @state    = hash[:state]
  @comments = hash[:comments]
end

Instance Attribute Details

#commentsObject (readonly)

Returns the value of attribute comments.



6
7
8
# File 'lib/postie/locality.rb', line 6

def comments
  @comments
end

#postcodeObject (readonly)

Returns the value of attribute postcode.



6
7
8
# File 'lib/postie/locality.rb', line 6

def postcode
  @postcode
end

#stateObject (readonly)

Returns the value of attribute state.



6
7
8
# File 'lib/postie/locality.rb', line 6

def state
  @state
end

#suburbObject (readonly)

Returns the value of attribute suburb.



6
7
8
# File 'lib/postie/locality.rb', line 6

def suburb
  @suburb
end

Class Method Details

.find(search) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/postie/locality.rb', line 15

def self.find(search)
  doc = Hpricot(open("http://auspostie.com/#{CGI.escape(search)}.xml"))
  (doc/"locality").collect do |locality|
    Locality.new(
      :postcode => locality.at("postcode").inner_html,
      :suburb   => locality.at("suburb").inner_html,
      :state    => locality.at("state").inner_html,
      :comments => locality.at("comments").inner_html
    )
  end
end