class PostcodeSoftware::Response
Groups together addresses and status information returned from the PostcodeSoftware.net web SDK.
Public Class Methods
new(xml)
click to toggle source
Initialise with the XML returned from the PostcodeSoftware
service.
The xml
parameter can be a filename, string or input stream as compatible with Nokogiri.
# File lib/postcode_software/response.rb, line 11 def initialize(xml) @doc = Nokogiri::XML(xml) @doc.remove_namespaces! end
Public Instance Methods
address_1()
click to toggle source
Street name of the postcode.
# File lib/postcode_software/response.rb, line 27 def address_1 try_content '//Address//Address1' end
address_2()
click to toggle source
Locality of the postcode or dependent street name if exists.
# File lib/postcode_software/response.rb, line 32 def address_2 try_content '//Address//Address2' end
address_3()
click to toggle source
Dependent Locality of the postcode.
# File lib/postcode_software/response.rb, line 37 def address_3 try_content '//Address//Address3' end
address_4()
click to toggle source
Double Dependent Locality of the postcode.
# File lib/postcode_software/response.rb, line 42 def address_4 try_content '//Address//Address4' end
county()
click to toggle source
County of the postcode.
# File lib/postcode_software/response.rb, line 52 def county try_content '//Address//County' end
error_message()
click to toggle source
Returns the error message.
# File lib/postcode_software/response.rb, line 22 def error_message @doc.at_xpath('//Address//ErrorMessage').content end
error_number()
click to toggle source
Returns the error number.
# File lib/postcode_software/response.rb, line 17 def error_number @doc.at_xpath('//Address//ErrorNumber').content.to_i end
postcode()
click to toggle source
Postcode that has been searched.
# File lib/postcode_software/response.rb, line 57 def postcode try_content '//Address//Postcode' end
premises()
click to toggle source
Returns premise data for this postcode.
[ { :organisation=>'Organisation', :building_details=>'Bulding Details', :number=>'123' }, ... ]
# 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()
click to toggle source
Town of the postcode.
# File lib/postcode_software/response.rb, line 47 def town try_content '//Address//Town' end
Private Instance Methods
try_content(path)
click to toggle source
# File lib/postcode_software/response.rb, line 87 def try_content(path) @doc.at_xpath(path).content if @doc.at_xpath(path) end