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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc16088ec67c078a87f2b689483b09fcafa994f3
4
- data.tar.gz: 298321db111e9788971b8414587ca308be36e01a
3
+ metadata.gz: 57386ed384eb3b234d7c24e6e607cfc6223f2bb7
4
+ data.tar.gz: ce4f672a178999536755c2c79e86ce93dfe4094b
5
5
  SHA512:
6
- metadata.gz: eb0e66b81cc9e74a32d22562e662b20ba6fa67e76a715d8d0b28885d1eef03270030a15168e0e119f633b5fe4f8f84f662affc2dfb2c4ecfc85c08a455944473
7
- data.tar.gz: fbf06dd63453d7e0d826b954239349880d88169f2867c78fa39fe9ed19fd5cb03b0bf8e85656966137cdc5bd6e8f1918c158d8bfc757d6f6a7a4f5040bdd30b1
6
+ metadata.gz: ac6e3bd30788ac73013c2e1acf300e48b76834599472c33e835a961b798b50df98348cfd8bded5b5cc46a8b76a798969e2b3474cfc8c7030eeabd3fa94f31ba9
7
+ data.tar.gz: ff5f7d24046d0fce2b2001c5f52b704f9cc2e55713e97faa96cbd71235ac17cfd40b7c013abbfcf8a746630ff78e28a9ab52a19eb2fdc20cc0cd1c6e8cfa21b3
data/.travis.yml CHANGED
@@ -1,6 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.9.2"
4
- - "1.9.3"
5
3
  - "2.0"
6
- script: rake
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- madison (0.3.1)
4
+ madison (0.4.0)
5
5
  json
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://secure.travis-ci.org/mdb/ruby-madison.png)](http://travis-ci.org/mdb/ruby-madison)
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
- gem install madison
13
+ ```
14
+ $ gem install madison
15
+ ```
14
16
 
15
- Alternatively, from source code:
17
+ ## Usage
16
18
 
17
- git clone https://github.com/mdb/madison.rb
18
- cd madison.rb
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
- ## Run Rspec tests
22
+ Require madison:
23
23
 
24
- (Assuming you've installed from source code)
24
+ ```ruby
25
+ require 'madison'
26
+ ```
25
27
 
26
- rake
28
+ ### Include it as a mixin
27
29
 
28
- ## View code coverage after running Rspec tests
30
+ ```ruby
31
+ class MyClass
32
+ include Madison
33
+ end
29
34
 
30
- (Again, assuming you've installed from source code)
35
+ my_class = MyClass.new
36
+ ```
31
37
 
32
- open coverage/index.html
38
+ Get a state's abbreviation:
33
39
 
34
- ## Usage
40
+ ```ruby
41
+ my_class.state_abbrev 'virginia'
42
+ # => VA
43
+ ```
35
44
 
36
- Require madison:
37
-
38
- require 'madison'
45
+ Get a state's name:
39
46
 
40
- Get a state's abbreviation:
47
+ ```ruby
48
+ my_class.state_name 'va'
49
+ # => Virginia
50
+ ```
41
51
 
42
- Madison.get_abbrev 'virginia' // 'VA'
52
+ Get an array of US state names/abbreviations:
43
53
 
44
- Get a state's name asynchronously:
54
+ ```ruby
55
+ my_class.states
56
+ # => [
57
+ # {
58
+ # name: 'Virginia',
59
+ # abbr: 'VA'
60
+ # },
61
+ # ...
62
+ #]
63
+ ```
45
64
 
46
- Madison.get_name 'va' // 'Virginia'
65
+ Get the Madison::Map class used
47
66
 
48
- Get a Ruby hash of US states, each containing 'name' and 'abbr' properties:
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
- Madison.states
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
@@ -1,3 +1,3 @@
1
1
  module Madison
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -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.3.1
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-08-30 00:00:00.000000000 Z
11
+ date: 2014-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json