area 0.5.1 → 0.6.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.
@@ -7,18 +7,8 @@ class Integer
7
7
  return row.last
8
8
  end
9
9
  end
10
- else # more than 3 digits, assume a zipcode
11
- Area::ZIP_CODES.each do |row|
12
- if row.first == self.to_s
13
- if options[:city]
14
- return row[1]
15
- elsif options[:state]
16
- return row[2]
17
- else
18
- return row[1] + ', ' + row[2]
19
- end
20
- end
21
- end
10
+ else
11
+ # puts "not an area code"
22
12
  end
23
13
  end
24
14
 
@@ -1,4 +1,5 @@
1
1
  class String
2
+
2
3
  def to_area
3
4
  @area_codes = []
4
5
  Area::AREA_CODES.each do |row|
@@ -13,6 +14,28 @@ class String
13
14
  end
14
15
  end
15
16
 
17
+ def to_region(options = {})
18
+ if self.to_s.length == 3 # an area code
19
+ Area::AREA_CODES.each do |row|
20
+ if row.first == self.to_s
21
+ return row.last
22
+ end
23
+ end
24
+ else # more than 3 digits, assume a zipcode
25
+ Area::ZIP_CODES.each do |row|
26
+ if row.first == self.to_s
27
+ if options[:city]
28
+ return row[1]
29
+ elsif options[:state]
30
+ return row[2]
31
+ else
32
+ return row[1] + ', ' + row[2]
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+
16
39
  def to_zip
17
40
  @zip_codes = []
18
41
 
@@ -1,3 +1,3 @@
1
1
  module Area
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -2,20 +2,12 @@ require 'minitest/autorun'
2
2
  require 'area'
3
3
 
4
4
  class TestInteger < MiniTest::Unit::TestCase
5
-
5
+
6
+
6
7
  def test_that_it_converts_area_code_to_region
7
8
  assert_equal "NY", 646.to_region
8
9
  end
9
10
 
10
- def test_that_it_converts_zip_code_to_region
11
- assert_equal "Brooklyn, NY", 11211.to_region
12
- end
13
-
14
- def test_that_it_supports_options
15
- assert_equal "Brooklyn", 11211.to_region(:city => true)
16
- assert_equal "NY", 11211.to_region(:state => true)
17
- end
18
-
19
11
  def test_that_it_converts_zip_code_to_latlon
20
12
  assert_equal "40.71209, -73.95427", 11211.to_latlon
21
13
  end
@@ -36,6 +28,19 @@ end
36
28
 
37
29
  class TestString < MiniTest::Unit::TestCase
38
30
 
31
+ def test_that_it_converts_area_code_to_region
32
+ assert_equal "NY", "646".to_region
33
+ end
34
+
35
+ def test_that_it_converts_zip_code_to_region
36
+ assert_equal "Brooklyn, NY", "11211".to_region
37
+ end
38
+
39
+ def test_that_it_supports_options
40
+ assert_equal "Brooklyn", "11211".to_region(:city => true)
41
+ assert_equal "NY", "11211".to_region(:state => true)
42
+ end
43
+
39
44
  def test_that_it_converts_to_area_code
40
45
  assert_equal "907", "AK".to_area
41
46
  assert_equal ["203", "860"], "CT".to_area
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.5.1
4
+ version: 0.6.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-07-27 00:00:00.000000000 Z
12
+ date: 2012-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fastercsv