Class: Postie::Locality
- Inherits:
-
Object
- Object
- Postie::Locality
- Defined in:
- lib/postie/locality.rb
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#postcode ⇒ Object
readonly
Returns the value of attribute postcode.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#suburb ⇒ Object
readonly
Returns the value of attribute suburb.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Locality
constructor
A new instance of Locality.
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
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
6 7 8 |
# File 'lib/postie/locality.rb', line 6 def comments @comments end |
#postcode ⇒ Object (readonly)
Returns the value of attribute postcode.
6 7 8 |
# File 'lib/postie/locality.rb', line 6 def postcode @postcode end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/postie/locality.rb', line 6 def state @state end |
#suburb ⇒ Object (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 |