madison 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/Gemfile.lock +1 -1
- data/README.md +72 -23
- data/lib/madison.rb +18 -0
- data/lib/madison/version.rb +1 -1
- data/spec/lib/madison_spec.rb +66 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57386ed384eb3b234d7c24e6e607cfc6223f2bb7
|
4
|
+
data.tar.gz: ce4f672a178999536755c2c79e86ce93dfe4094b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac6e3bd30788ac73013c2e1acf300e48b76834599472c33e835a961b798b50df98348cfd8bded5b5cc46a8b76a798969e2b3474cfc8c7030eeabd3fa94f31ba9
|
7
|
+
data.tar.gz: ff5f7d24046d0fce2b2001c5f52b704f9cc2e55713e97faa96cbd71235ac17cfd40b7c013abbfcf8a746630ff78e28a9ab52a19eb2fdc20cc0cd1c6e8cfa21b3
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://
|
1
|
+
[![Build Status](https://travis-ci.org/mdb/madison.rb.svg?branch=master)](https://travis-ci.org/mdb/madison.rb)
|
2
2
|
|
3
3
|
# madison
|
4
4
|
|
@@ -10,41 +10,90 @@ This is the Ruby version of the Node.js [madison](http://github.com/mdb/madison)
|
|
10
10
|
|
11
11
|
The released gem (recommended):
|
12
12
|
|
13
|
-
|
13
|
+
```
|
14
|
+
$ gem install madison
|
15
|
+
```
|
14
16
|
|
15
|
-
|
17
|
+
## Usage
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
bundle install
|
20
|
-
rake install
|
19
|
+
Madison can be mixed into a class, or its singleton methods
|
20
|
+
can be called directly on the `Madison` module.
|
21
21
|
|
22
|
-
|
22
|
+
Require madison:
|
23
23
|
|
24
|
-
|
24
|
+
```ruby
|
25
|
+
require 'madison'
|
26
|
+
```
|
25
27
|
|
26
|
-
|
28
|
+
### Include it as a mixin
|
27
29
|
|
28
|
-
|
30
|
+
```ruby
|
31
|
+
class MyClass
|
32
|
+
include Madison
|
33
|
+
end
|
29
34
|
|
30
|
-
|
35
|
+
my_class = MyClass.new
|
36
|
+
```
|
31
37
|
|
32
|
-
|
38
|
+
Get a state's abbreviation:
|
33
39
|
|
34
|
-
|
40
|
+
```ruby
|
41
|
+
my_class.state_abbrev 'virginia'
|
42
|
+
# => VA
|
43
|
+
```
|
35
44
|
|
36
|
-
|
37
|
-
|
38
|
-
require 'madison'
|
45
|
+
Get a state's name:
|
39
46
|
|
40
|
-
|
47
|
+
```ruby
|
48
|
+
my_class.state_name 'va'
|
49
|
+
# => Virginia
|
50
|
+
```
|
41
51
|
|
42
|
-
|
52
|
+
Get an array of US state names/abbreviations:
|
43
53
|
|
44
|
-
|
54
|
+
```ruby
|
55
|
+
my_class.states
|
56
|
+
# => [
|
57
|
+
# {
|
58
|
+
# name: 'Virginia',
|
59
|
+
# abbr: 'VA'
|
60
|
+
# },
|
61
|
+
# ...
|
62
|
+
#]
|
63
|
+
```
|
45
64
|
|
46
|
-
|
65
|
+
Get the Madison::Map class used
|
47
66
|
|
48
|
-
|
67
|
+
```ruby
|
68
|
+
my_class.madison_map
|
69
|
+
# => <Madison::Map:0x007f8dbc80e7f0>
|
70
|
+
```
|
71
|
+
|
72
|
+
### Use its singleton methods on the Madison module
|
73
|
+
|
74
|
+
Get a state's abbreviation:
|
49
75
|
|
50
|
-
|
76
|
+
```ruby
|
77
|
+
Madison.get_abbrev 'virginia'
|
78
|
+
# => VA
|
79
|
+
```
|
80
|
+
|
81
|
+
Get a state's name:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
Madison.get_name 'va'
|
85
|
+
# => Virginia
|
86
|
+
```
|
87
|
+
|
88
|
+
Get an array of US state names/abbreviations:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
Madison.states
|
92
|
+
# => [
|
93
|
+
# {
|
94
|
+
# name: 'Virginia',
|
95
|
+
# abbr: 'VA'
|
96
|
+
# },
|
97
|
+
# ...
|
98
|
+
#]
|
99
|
+
```
|
data/lib/madison.rb
CHANGED
@@ -15,4 +15,22 @@ module Madison
|
|
15
15
|
def self.get_name(abbrev)
|
16
16
|
@map.get_name(abbrev)
|
17
17
|
end
|
18
|
+
|
19
|
+
# mixin methods
|
20
|
+
|
21
|
+
def states
|
22
|
+
madison_map.states
|
23
|
+
end
|
24
|
+
|
25
|
+
def state_name(abbrev)
|
26
|
+
madison_map.get_name(abbrev)
|
27
|
+
end
|
28
|
+
|
29
|
+
def state_abbrev(name)
|
30
|
+
madison_map.get_abbrev(name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def madison_map
|
34
|
+
@madison_map ||= Madison::Map.new
|
35
|
+
end
|
18
36
|
end
|
data/lib/madison/version.rb
CHANGED
data/spec/lib/madison_spec.rb
CHANGED
@@ -80,4 +80,70 @@ describe Madison do
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
context 'the methods it provides a class when it is mixed into the class' do
|
85
|
+
include Madison
|
86
|
+
|
87
|
+
describe '#states' do
|
88
|
+
it 'returns an array of state names & abbreviations' do
|
89
|
+
expect(states.length).to eq 51
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'each hash in the states array' do
|
93
|
+
it 'has a "name" key' do
|
94
|
+
expect(states[0]['name']).to eq 'Alabama'
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'has an "abbrev" key' do
|
98
|
+
expect(states[0]['abbr']).to eq 'AL'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#state_name' do
|
104
|
+
context 'when it is passed an abbreviation' do
|
105
|
+
it 'returns the correct state name' do
|
106
|
+
expect(state_name 'va').to eq 'Virginia'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when it is passed an invalid abbreviation' do
|
111
|
+
it 'returns nil' do
|
112
|
+
expect(state_name 'xx').to eq nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when it is not passed an argument' do
|
117
|
+
it 'raises an error' do
|
118
|
+
expect { state_name }.to raise_error
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '#state_abbrev' do
|
124
|
+
context 'when it is passed a state name' do
|
125
|
+
it 'returns the correct state abbreviation' do
|
126
|
+
expect(state_abbrev 'virginia').to eq 'VA'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when it is passed an invalid name' do
|
131
|
+
it 'returns nil' do
|
132
|
+
expect(state_abbrev 'fake_state').to eq nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'when it is not passed an argument' do
|
137
|
+
it 'raises an error' do
|
138
|
+
expect { state_abbrev }.to raise_error
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#madison_map' do
|
144
|
+
it 'returns an instance of a Madison::Map class' do
|
145
|
+
expect(madison_map.class).to eq Madison::Map
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
83
149
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: madison
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Ball
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|