area 0.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/area.rb +4 -96
  2. data/readme.md +19 -2
  3. metadata +2 -2
data/lib/area.rb CHANGED
@@ -5,6 +5,10 @@ else
5
5
  require 'faster_csv'
6
6
  end
7
7
 
8
+ require 'area/array'
9
+ require 'area/integer'
10
+ require 'area/string'
11
+
8
12
  module Area
9
13
 
10
14
  zip_path = File.open(File.join(File.dirname(__FILE__), '..', 'data', 'zipcodes.csv'))
@@ -19,99 +23,3 @@ module Area
19
23
  ZIP_CODES = FasterCSV.parse(zip_path)
20
24
  end
21
25
  end
22
-
23
- class Integer
24
- def to_region(options = {})
25
- if self.to_s.length == 3 # an area code
26
- Area::AREA_CODES.each do |row|
27
- if row.first == self.to_s
28
- return row.last
29
- end
30
- end
31
- else # more than 3 digits, assume a zipcode
32
- Area::ZIP_CODES.each do |row|
33
- if row.first == self.to_s
34
- if options[:city]
35
- return row[1]
36
- elsif options[:state]
37
- return row[2]
38
- else
39
- return row[1] + ', ' + row[2]
40
- end
41
- end
42
- end
43
- end
44
- end
45
-
46
- def to_latlon
47
- Area::ZIP_CODES.each do |row|
48
- if row.first == self.to_s
49
- return row[3] + ', ' + row[4]
50
- end
51
- end
52
- end
53
-
54
- def to_lat
55
- Area::ZIP_CODES.each do |row|
56
- if row.first == self.to_s
57
- return row[3]
58
- end
59
- end
60
- end
61
-
62
- def to_lon
63
- Area::ZIP_CODES.each do |row|
64
- if row.first == self.to_s
65
- return row[4]
66
- end
67
- end
68
- end
69
-
70
- def to_gmt_offset
71
- Area::ZIP_CODES.each do |row|
72
- if row.first == self.to_s
73
- return row[5]
74
- end
75
- end
76
- end
77
-
78
- end
79
-
80
- class String
81
- def to_area
82
- @area_codes = []
83
- Area::AREA_CODES.each do |row|
84
- if row[1].upcase == self
85
- @area_codes.push(row.first)
86
- end
87
- end
88
- if @area_codes.length == 1
89
- return @area_codes.first
90
- else
91
- return @area_codes
92
- end
93
- end
94
-
95
- def to_zip
96
- @zip_codes = []
97
- Area::ZIP_CODES.each do |row|
98
- if row[1] and row[1].downcase == self.downcase
99
- @zip_codes.push(row.first)
100
- end
101
- end
102
- if @zip_codes.length == 1
103
- return @zip_codes.first
104
- else
105
- return @zip_codes
106
- end
107
- end
108
-
109
- def to_gmt_offset
110
- Area::ZIP_CODES.each do |row|
111
- if row[2].upcase == self.to_s.upcase
112
- return row[5]
113
- end
114
- end
115
- end
116
-
117
- end
data/readme.md CHANGED
@@ -1,5 +1,4 @@
1
1
  [![Build Status](https://secure.travis-ci.org/jgv/area.png)](http://travis-ci.org/jgv/area)
2
-
3
2
  # Area
4
3
 
5
4
  Hi. This gem allows you to perform the following conversions:
@@ -12,8 +11,11 @@ Hi. This gem allows you to perform the following conversions:
12
11
  * A zipcode to just a lon
13
12
  * A zipcode to its GMT offset
14
13
  * A state to its GMT offset
14
+ * A lat/lon pair to a region
15
+ * A lat/lon pair to its GMT offset
16
+ * A lat/lon pair to its zip code
15
17
 
16
- Area uses public domain data and does not rely on any external services.
18
+ Area uses public domain data and does not rely on any external services (the internets). Usage is meant to be more lightweight than the Geocoder gem.
17
19
 
18
20
  ## Installation
19
21
 
@@ -64,6 +66,21 @@ In your gemfile: `gem 'area'`
64
66
  "NY".to_gmt_offset #=> "-5" # by state
65
67
  ```
66
68
 
69
+ #### Convert a lat/lon pair to a zipcode
70
+ ```` ruby
71
+ [40.71209, -73.95427].to_zip #=> "11211"
72
+ ```
73
+
74
+ #### Convert a lat/lon pair to a region
75
+ ```` ruby
76
+ [40.71209, -73.95427].to_region #=> "Brooklyn, NY"
77
+ ```
78
+
79
+ #### Get the GMT offset for a lat/lon pair
80
+ ```` ruby
81
+ [40.71209, -73.95427].to_gmt_offset #=> "-5"
82
+ ```
83
+
67
84
  ## Testing and Contributing and Stuff
68
85
 
69
86
  Contributions are more than welcome. I'm [testing](http://travis-ci.org/jgv/area) with minitest. This gem supports:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: area
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-23 00:00:00.000000000 Z
12
+ date: 2012-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fastercsv