postcode 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,3 @@
1
1
  require "fastercsv"
2
+ require "activesupport"
2
3
  require File.dirname(__FILE__) + "/postcode/uk"
@@ -1,13 +1,22 @@
1
1
  module PostCode
2
2
  class UK
3
- attr_accessor :postcode, :latitude, :longitude
3
+ attr_accessor :outward, :inward, :latitude, :longitude
4
4
 
5
- def initialize(postcode, latitude, longitude)
6
- self.postcode = postcode
5
+ def initialize(outward, inward, latitude, longitude)
6
+ self.outward = outward
7
+ self.inward = inward
7
8
  self.latitude = latitude
8
9
  self.longitude = longitude
9
10
  end
10
11
 
12
+ def unit
13
+ "#{outward} #{inward}"
14
+ end
15
+
16
+ def to_s
17
+ unit
18
+ end
19
+
11
20
  class << self
12
21
  def database=(path)
13
22
  @database = FasterCSV.read(path, :col_sep => " ")
@@ -22,12 +31,12 @@ module PostCode
22
31
  end
23
32
 
24
33
  def lookup(postcode)
25
- postcode.gsub!(/\s+/, "")
34
+ postcode.gsub!(/\s+/, "").downcase!
26
35
 
27
- data = @database.select {|row| row if "#{row[2]}#{row[3]}" == postcode }.first
36
+ data = database.select {|row| row if "#{row[2]}#{row[3]}".downcase == postcode }.first
28
37
 
29
- if data.size > 0
30
- self.new(postcode, data[0], data[1])
38
+ if data
39
+ self.new(data[2], data[3], data[0], data[1])
31
40
  end
32
41
  end
33
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Bartholomew
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
25
35
  description: ""
26
36
  email: Stephen Bartholomew
27
37
  executables: []
@@ -34,13 +44,14 @@ files:
34
44
  - README
35
45
  - Rakefile
36
46
  - VERSION
47
+ - databases/database.uk.txt
37
48
  - lib/postcode.rb
38
49
  - lib/postcode/uk.rb
39
50
  - spec/fixtures/database.uk.txt
40
51
  - spec/postcode_spec.rb
41
52
  - spec/spec.opts
42
53
  has_rdoc: true
43
- homepage: http://github.com/curve21/post_code
54
+ homepage: http://github.com/curve21/postcode
44
55
  licenses: []
45
56
 
46
57
  post_install_message: