Class: PostCode::UK
- Inherits:
-
Object
- Object
- PostCode::UK
- Defined in:
- lib/postcode/uk.rb
Instance Attribute Summary collapse
-
#inward ⇒ Object
Returns the value of attribute inward.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#outward ⇒ Object
Returns the value of attribute outward.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(outward, inward, latitude, longitude) ⇒ UK
constructor
A new instance of UK.
- #to_s ⇒ Object
- #unit ⇒ Object
Constructor Details
#initialize(outward, inward, latitude, longitude) ⇒ UK
Returns a new instance of UK.
5 6 7 8 9 10 |
# File 'lib/postcode/uk.rb', line 5 def initialize(outward, inward, latitude, longitude) self.outward = outward self.inward = inward self.latitude = latitude self.longitude = longitude end |
Instance Attribute Details
#inward ⇒ Object
Returns the value of attribute inward.
3 4 5 |
# File 'lib/postcode/uk.rb', line 3 def inward @inward end |
#latitude ⇒ Object
Returns the value of attribute latitude.
3 4 5 |
# File 'lib/postcode/uk.rb', line 3 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
3 4 5 |
# File 'lib/postcode/uk.rb', line 3 def longitude @longitude end |
#outward ⇒ Object
Returns the value of attribute outward.
3 4 5 |
# File 'lib/postcode/uk.rb', line 3 def outward @outward end |
Class Method Details
.database ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/postcode/uk.rb', line 25 def database if !@database self.database = File.dirname(__FILE__) + "/../../databases/database.uk.txt" end @database end |
.database=(path) ⇒ Object
21 22 23 |
# File 'lib/postcode/uk.rb', line 21 def database=(path) @database = FasterCSV.read(path, :col_sep => " ") end |
.lookup(postcode) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/postcode/uk.rb', line 33 def lookup(postcode) postcode.gsub!(/\s+/, "").downcase! data = database.select {|row| row if "#{row[2]}#{row[3]}".downcase == postcode }.first if data self.new(data[2], data[3], data[0], data[1]) end end |
Instance Method Details
#to_s ⇒ Object
16 17 18 |
# File 'lib/postcode/uk.rb', line 16 def to_s unit end |
#unit ⇒ Object
12 13 14 |
# File 'lib/postcode/uk.rb', line 12 def unit "#{outward} #{inward}" end |