Class: Postcodes::Postcode
- Inherits:
-
Object
- Object
- Postcodes::Postcode
- Defined in:
- lib/postcodes/postcode.rb
Instance Attribute Summary collapse
-
#addresses ⇒ Object
readonly
Returns the value of attribute addresses.
-
#postcode ⇒ Object
readonly
Returns the value of attribute postcode.
-
#postcode_data ⇒ Object
readonly
Returns the value of attribute postcode_data.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(postcode = nil, postcode_data = nil) ⇒ Postcode
constructor
A new instance of Postcode.
- #to_s ⇒ Object
Constructor Details
#initialize(postcode = nil, postcode_data = nil) ⇒ Postcode
Returns a new instance of Postcode.
6 7 8 9 10 |
# File 'lib/postcodes/postcode.rb', line 6 def initialize(postcode = nil, postcode_data = nil) @raw = postcode_data @addresses = (postcode_data.nil? || postcode_data[:result].nil?) ? [] : postcode_data[:result] @postcode = postcode end |
Instance Attribute Details
#addresses ⇒ Object (readonly)
Returns the value of attribute addresses.
4 5 6 |
# File 'lib/postcodes/postcode.rb', line 4 def addresses @addresses end |
#postcode ⇒ Object (readonly)
Returns the value of attribute postcode.
4 5 6 |
# File 'lib/postcodes/postcode.rb', line 4 def postcode @postcode end |
#postcode_data ⇒ Object (readonly)
Returns the value of attribute postcode_data.
4 5 6 |
# File 'lib/postcodes/postcode.rb', line 4 def postcode_data @postcode_data end |
Class Method Details
.lookup(postcode) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/postcodes/postcode.rb', line 12 def self.lookup(postcode) begin response = Postcodes.request :get, "postcodes/#{postcode}" rescue Postcodes::ResourceNotFoundError => error raise error unless error.response_code == 4040 response = nil end new postcode, response end |
Instance Method Details
#empty? ⇒ Boolean
22 23 24 |
# File 'lib/postcodes/postcode.rb', line 22 def empty? @raw.nil? end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/postcodes/postcode.rb', line 30 def to_s addresses.to_s end |