Class: PostcodeInfo::Postcode
- Inherits:
-
Object
- Object
- PostcodeInfo::Postcode
- Defined in:
- lib/postcodeinfo/postcode.rb
Instance Attribute Summary collapse
-
#as_given ⇒ Object
readonly
these attributes are set on construction.
-
#client ⇒ Object
Returns the value of attribute client.
-
#normalised ⇒ Object
readonly
these attributes are set on construction.
Class Method Summary collapse
Instance Method Summary collapse
- #addresses ⇒ Object (also: #lookup_addresses!)
- #country ⇒ Object
-
#initialize(given_postcode, client) ⇒ Postcode
constructor
these attributes require lookups attr_reader :latitude, :longitude, :addresses, :local_authority.
- #latitude ⇒ Object
- #local_authority ⇒ Object
- #longitude ⇒ Object
- #lookup_info! ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(given_postcode, client) ⇒ Postcode
these attributes require lookups attr_reader :latitude, :longitude, :addresses, :local_authority
9 10 11 12 13 14 |
# File 'lib/postcodeinfo/postcode.rb', line 9 def initialize(given_postcode, client) @as_given = given_postcode @normalised = self.class.normalise(@as_given) @client = client @info = nil end |
Instance Attribute Details
#as_given ⇒ Object (readonly)
these attributes are set on construction
4 5 6 |
# File 'lib/postcodeinfo/postcode.rb', line 4 def as_given @as_given end |
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/postcodeinfo/postcode.rb', line 5 def client @client end |
#normalised ⇒ Object (readonly)
these attributes are set on construction
4 5 6 |
# File 'lib/postcodeinfo/postcode.rb', line 4 def normalised @normalised end |
Class Method Details
.normalise(postcode) ⇒ Object
16 17 18 |
# File 'lib/postcodeinfo/postcode.rb', line 16 def self.normalise(postcode) postcode.downcase.gsub(/[^a-z0-9]/, '') end |
Instance Method Details
#addresses ⇒ Object Also known as: lookup_addresses!
40 41 42 |
# File 'lib/postcodeinfo/postcode.rb', line 40 def addresses @addresses ||= @client.addresses(@normalised) end |
#country ⇒ Object
35 36 37 38 |
# File 'lib/postcodeinfo/postcode.rb', line 35 def country lookup_info! if @info.nil? @country end |
#latitude ⇒ Object
20 21 22 23 |
# File 'lib/postcodeinfo/postcode.rb', line 20 def latitude lookup_info! if @info.nil? @latitude end |
#local_authority ⇒ Object
30 31 32 33 |
# File 'lib/postcodeinfo/postcode.rb', line 30 def lookup_info! if @info.nil? @local_authority end |
#longitude ⇒ Object
25 26 27 28 |
# File 'lib/postcodeinfo/postcode.rb', line 25 def longitude lookup_info! if @info.nil? @longitude end |
#lookup_info! ⇒ Object
49 50 51 52 |
# File 'lib/postcodeinfo/postcode.rb', line 49 def lookup_info! @info = @client.info(@normalised) parse_info! end |
#valid? ⇒ Boolean
45 46 47 |
# File 'lib/postcodeinfo/postcode.rb', line 45 def valid? @valid ||= @client.valid?(@normalised) end |