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