geographer 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -11
- data/VERSION +1 -1
- data/geographer.gemspec +1 -1
- data/lib/geographer/us/states.rb +97 -91
- data/lib/geographer.rb +1 -1
- data/test/geographer/us/states_test.rb +6 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -29,42 +29,45 @@ Add to environment file:
|
|
29
29
|
|
30
30
|
config.gem "geographer", :version => '1.0.0', :source => 'http://gemcutter.org'
|
31
31
|
|
32
|
-
You
|
32
|
+
You will need to create classes and include modules in order to use geographer. You can do this in the lib directory,
|
33
|
+
an initializer, etc.:
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
class States
|
36
|
+
include Geographer::Us::States
|
37
|
+
end
|
37
38
|
|
38
39
|
|
39
40
|
== USAGE
|
40
41
|
|
42
|
+
The examples are based on the States class created above.
|
43
|
+
|
41
44
|
For a list (array) of state abbreviations:
|
42
45
|
|
43
|
-
|
46
|
+
States.abbreviations
|
44
47
|
|
45
48
|
For a list (array) of state names:
|
46
49
|
|
47
|
-
|
50
|
+
States.names
|
48
51
|
|
49
52
|
For a list (array) of state abbreviations with US territories:
|
50
53
|
|
51
|
-
|
54
|
+
States.abbreviations_with_territories
|
52
55
|
|
53
56
|
For a list (array) of state names with US territories:
|
54
57
|
|
55
|
-
|
58
|
+
States.names_with_territories
|
56
59
|
|
57
60
|
For a list (array) of territory abbreviations:
|
58
61
|
|
59
|
-
|
62
|
+
States.territories_abbreviations
|
60
63
|
|
61
64
|
For a list (array) of territory names:
|
62
65
|
|
63
|
-
|
66
|
+
States.territories_names
|
64
67
|
|
65
68
|
To look up the full name from the abbreviation:
|
66
69
|
|
67
|
-
|
70
|
+
States.abbreviations_name_map['AL'] # returns 'Alabama'
|
68
71
|
|
69
72
|
|
70
73
|
== LICENSE
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/geographer.gemspec
CHANGED
data/lib/geographer/us/states.rb
CHANGED
@@ -4,105 +4,111 @@ module Geographer
|
|
4
4
|
# Provides a list of US States abbreviations (with and without territories), names and a map of
|
5
5
|
# abbreviations to names.
|
6
6
|
#
|
7
|
-
|
7
|
+
module States
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
def self.abbreviations
|
12
|
-
self.abbreviations_with_territories - self.territories_abbreviations
|
9
|
+
def self.included( base )
|
10
|
+
base.extend( ClassMethods )
|
13
11
|
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
# A list of abbreviatons of US States and territories.
|
15
|
+
#
|
16
|
+
def abbreviations
|
17
|
+
self.abbreviations_with_territories - self.territories_abbreviations
|
18
|
+
end
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
# A list of names of US States only (no territories).
|
21
|
+
#
|
22
|
+
def names
|
23
|
+
self.names_with_territories - self.territories_names
|
24
|
+
end
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
# A list of abbreviatons of US States and territories.
|
27
|
+
#
|
28
|
+
def abbreviations_with_territories
|
29
|
+
self.abbreviations_name_map.keys.sort
|
30
|
+
end
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
# A list of names of US States and territories.
|
33
|
+
#
|
34
|
+
def names_with_territories
|
35
|
+
self.abbreviations_name_map.values.sort
|
36
|
+
end
|
32
37
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
# A list of abbreviatons of US territories.
|
39
|
+
#
|
40
|
+
def territories_abbreviations
|
41
|
+
%w( AS FM GU MH PW PR VI )
|
42
|
+
end
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
def territories_names
|
45
|
+
[ "American Samoa", "Guam", "Islands", "Micronesia", "Palau", "Puerto Rico", "Virgin Island" ]
|
46
|
+
end
|
42
47
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
48
|
+
# An index (map) of US States and territories abbreviations and full names.
|
49
|
+
#
|
50
|
+
def abbreviations_name_map
|
51
|
+
{
|
52
|
+
'AL' => 'Alabama',
|
53
|
+
'AK' => 'Alaska',
|
54
|
+
'AS' => 'American Samoa',
|
55
|
+
'AZ' => 'Arizona',
|
56
|
+
'AR' => 'Arkansas',
|
57
|
+
'CA' => 'California',
|
58
|
+
'CO' => 'Colorado',
|
59
|
+
'CT' => 'Connecticut',
|
60
|
+
'DE' => 'Delaware',
|
61
|
+
'DC' => 'District of Columbia',
|
62
|
+
'FM' => 'Micronesia',
|
63
|
+
'FL' => 'Florida',
|
64
|
+
'GA' => 'Georgia',
|
65
|
+
'GU' => 'Guam',
|
66
|
+
'HI' => 'Hawaii',
|
67
|
+
'ID' => 'Idaho',
|
68
|
+
'IL' => 'Illinois',
|
69
|
+
'IN' => 'Indiana',
|
70
|
+
'IA' => 'Iowa',
|
71
|
+
'KS' => 'Kansas',
|
72
|
+
'KY' => 'Kentucky',
|
73
|
+
'LA' => 'Louisiana',
|
74
|
+
'ME' => 'Maine',
|
75
|
+
'MH' => 'Islands',
|
76
|
+
'MD' => 'Maryland',
|
77
|
+
'MA' => 'Massachusetts',
|
78
|
+
'MI' => 'Michigan',
|
79
|
+
'MN' => 'Minnesota',
|
80
|
+
'MS' => 'Mississippi',
|
81
|
+
'MO' => 'Missouri',
|
82
|
+
'MT' => 'Montana',
|
83
|
+
'NE' => 'Nebraska',
|
84
|
+
'NV' => 'Nevada',
|
85
|
+
'NH' => 'New Hampshire',
|
86
|
+
'NJ' => 'New Jersey',
|
87
|
+
'NM' => 'New Mexico',
|
88
|
+
'NY' => 'New York',
|
89
|
+
'NC' => 'North Carolina',
|
90
|
+
'ND' => 'North Dakota',
|
91
|
+
'OH' => 'Ohio',
|
92
|
+
'OK' => 'Oklahoma',
|
93
|
+
'OR' => 'Oregon',
|
94
|
+
'PW' => 'Palau',
|
95
|
+
'PA' => 'Pennsylvania',
|
96
|
+
'PR' => 'Puerto Rico',
|
97
|
+
'RI' => 'Rhode Island',
|
98
|
+
'SC' => 'South Carolina',
|
99
|
+
'SD' => 'South Dakota',
|
100
|
+
'TN' => 'Tennessee',
|
101
|
+
'TX' => 'Texas',
|
102
|
+
'UT' => 'Utah',
|
103
|
+
'VT' => 'Vermont',
|
104
|
+
'VI' => 'Virgin Island',
|
105
|
+
'VA' => 'Virginia',
|
106
|
+
'WA' => 'Washington',
|
107
|
+
'WV' => 'West Virginia',
|
108
|
+
'WI' => 'Wisconsin',
|
109
|
+
'WY' => 'Wyoming'
|
110
|
+
}
|
111
|
+
end
|
106
112
|
end
|
107
113
|
end
|
108
114
|
end
|
data/lib/geographer.rb
CHANGED
@@ -2,6 +2,12 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class StatesTest < Test::Unit::TestCase
|
4
4
|
context "states" do
|
5
|
+
setup do
|
6
|
+
class States
|
7
|
+
include Geographer::Us::States
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
context "abbreviations" do
|
6
12
|
setup do
|
7
13
|
@states = %w( AK AL AR AZ CA CO CT DC DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO MS MT NC ND NE NH NJ NM NV NY
|