Class: PostcodeSoftware::Response
- Inherits:
-
Object
- Object
- PostcodeSoftware::Response
- Defined in:
- lib/postcode_software/response.rb
Overview
Groups together addresses and status information returned from the PostcodeSoftware.net web SDK.
Instance Method Summary collapse
-
#address_1 ⇒ Object
Street name of the postcode.
-
#address_2 ⇒ Object
Locality of the postcode or dependent street name if exists.
-
#address_3 ⇒ Object
Dependent Locality of the postcode.
-
#address_4 ⇒ Object
Double Dependent Locality of the postcode.
-
#county ⇒ Object
County of the postcode.
-
#error_message ⇒ Object
Returns the error message.
-
#error_number ⇒ Object
Returns the error number.
-
#initialize(xml) ⇒ Response
constructor
Initialise with the XML returned from the PostcodeSoftware service.
-
#postcode ⇒ Object
Postcode that has been searched.
-
#premises ⇒ Object
Returns premise data for this postcode.
-
#town ⇒ Object
Town of the postcode.
Constructor Details
#initialize(xml) ⇒ Response
Initialise with the XML returned from the PostcodeSoftware service.
The xml parameter can be a filename, string or input stream as compatible with Nokogiri.
11 12 13 14 |
# File 'lib/postcode_software/response.rb', line 11 def initialize(xml) @doc = Nokogiri::XML(xml) @doc.remove_namespaces! end |
Instance Method Details
#address_1 ⇒ Object
Street name of the postcode.
27 28 29 |
# File 'lib/postcode_software/response.rb', line 27 def address_1 try_content '//Address//Address1' end |
#address_2 ⇒ Object
Locality of the postcode or dependent street name if exists.
32 33 34 |
# File 'lib/postcode_software/response.rb', line 32 def address_2 try_content '//Address//Address2' end |
#address_3 ⇒ Object
Dependent Locality of the postcode.
37 38 39 |
# File 'lib/postcode_software/response.rb', line 37 def address_3 try_content '//Address//Address3' end |
#address_4 ⇒ Object
Double Dependent Locality of the postcode.
42 43 44 |
# File 'lib/postcode_software/response.rb', line 42 def address_4 try_content '//Address//Address4' end |
#county ⇒ Object
County of the postcode.
52 53 54 |
# File 'lib/postcode_software/response.rb', line 52 def county try_content '//Address//County' end |
#error_message ⇒ Object
Returns the error message.
22 23 24 |
# File 'lib/postcode_software/response.rb', line 22 def @doc.at_xpath('//Address//ErrorMessage').content end |
#error_number ⇒ Object
Returns the error number.
17 18 19 |
# File 'lib/postcode_software/response.rb', line 17 def error_number @doc.at_xpath('//Address//ErrorNumber').content.to_i end |
#postcode ⇒ Object
Postcode that has been searched.
57 58 59 |
# File 'lib/postcode_software/response.rb', line 57 def postcode try_content '//Address//Postcode' end |
#premises ⇒ Object
Returns premise data for this postcode.
[
{
:organisation=>'Organisation',
:building_details=>'Bulding Details',
:number=>'123'
},
...
]
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/postcode_software/response.rb', line 71 def premises if @doc.at_xpath('//Address//PremiseData') str = @doc.at_xpath('//Address//PremiseData').content str .split(';') .map do |x| y = x.split('|', -1) {organisation:y[0], building_details:y[1], number:y[2]} end else [] end end |
#town ⇒ Object
Town of the postcode.
47 48 49 |
# File 'lib/postcode_software/response.rb', line 47 def town try_content '//Address//Town' end |