digital_opera 0.0.12 → 0.0.13
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.
- data/Gemfile.lock +1 -1
- data/README.md +9 -3
- data/lib/digital_opera/states.rb +85 -0
- data/lib/digital_opera/version.rb +1 -1
- data/spec/lib/digital_opera/states_spec.rb +145 -0
- metadata +11 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
-

|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/digital_opera)
|
4
4
|
|
5
|
-
This Gem was created to store all of the crazy tricks, hacks and practices used by Digital Opera in various Ruby
|
6
|
-
based projects. We figured it was easier to throw them all in a Gem than to keep copying them into projects
|
5
|
+
This Gem was created to store all of the crazy tricks, hacks and practices used by Digital Opera in various Ruby
|
6
|
+
based projects. We figured it was easier to throw them all in a Gem than to keep copying them into projects
|
7
7
|
independently, and then we thought...maybe someone else would find them useful too!
|
8
8
|
|
9
9
|
If you do find this Gem to be useful, please let us know.
|
10
10
|
|
11
|
+
### Version 0.0.13
|
12
|
+
- Added [DigitalOpera::States](https://github.com/noiseunion/do-toolbox/wiki/DigitalOpera::States). This file is not included by default. Be sure to add `require 'digital_opera/states'` in the application.rb
|
13
|
+
|
14
|
+
### Version 0.0.12
|
15
|
+
- Bug fix in Banker - was causing float multiplication rounding error
|
16
|
+
|
11
17
|
### Version 0.0.10
|
12
18
|
- Bug fix in [ellipsis.js.coffee](https://github.com/noiseunion/do-toolbox/wiki/ellipsis.js.coffee)
|
13
19
|
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module DigitalOpera
|
2
|
+
class States
|
3
|
+
US_STATES = [
|
4
|
+
['Alabama', 'AL'],
|
5
|
+
['Alaska', 'AK'],
|
6
|
+
['Arizona', 'AZ'],
|
7
|
+
['Arkansas', 'AR'],
|
8
|
+
['California', 'CA'],
|
9
|
+
['Colorado', 'CO'],
|
10
|
+
['Connecticut', 'CT'],
|
11
|
+
['Delaware', 'DE'],
|
12
|
+
['District of Columbia', 'DC'],
|
13
|
+
['Florida', 'FL'],
|
14
|
+
['Georgia', 'GA'],
|
15
|
+
['Hawaii', 'HI'],
|
16
|
+
['Idaho', 'ID'],
|
17
|
+
['Illinois', 'IL'],
|
18
|
+
['Indiana', 'IN'],
|
19
|
+
['Iowa', 'IA'],
|
20
|
+
['Kansas', 'KS'],
|
21
|
+
['Kentucky', 'KY'],
|
22
|
+
['Louisiana', 'LA'],
|
23
|
+
['Maine', 'ME'],
|
24
|
+
['Maryland', 'MD'],
|
25
|
+
['Massachusetts', 'MA'],
|
26
|
+
['Michigan', 'MI'],
|
27
|
+
['Minnesota', 'MN'],
|
28
|
+
['Mississippi', 'MS'],
|
29
|
+
['Missouri', 'MO'],
|
30
|
+
['Montana', 'MT'],
|
31
|
+
['Nebraska', 'NE'],
|
32
|
+
['Nevada', 'NV'],
|
33
|
+
['New Hampshire', 'NH'],
|
34
|
+
['New Jersey', 'NJ'],
|
35
|
+
['New Mexico', 'NM'],
|
36
|
+
['New York', 'NY'],
|
37
|
+
['North Carolina', 'NC'],
|
38
|
+
['North Dakota', 'ND'],
|
39
|
+
['Ohio', 'OH'],
|
40
|
+
['Oklahoma', 'OK'],
|
41
|
+
['Oregon', 'OR'],
|
42
|
+
['Pennsylvania', 'PA'],
|
43
|
+
['Rhode Island', 'RI'],
|
44
|
+
['South Carolina', 'SC'],
|
45
|
+
['South Dakota', 'SD'],
|
46
|
+
['Tennessee', 'TN'],
|
47
|
+
['Texas', 'TX'],
|
48
|
+
['Utah', 'UT'],
|
49
|
+
['Vermont', 'VT'],
|
50
|
+
['Virginia', 'VA'],
|
51
|
+
['Washington', 'WA'],
|
52
|
+
['West Virginia', 'WV'],
|
53
|
+
['Wisconsin', 'WI'],
|
54
|
+
['Wyoming', 'WY']
|
55
|
+
]
|
56
|
+
|
57
|
+
def self.to_collection
|
58
|
+
@collection ||= US_STATES.sort{|a, b| a.first <=> b.first }
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.abbreviations
|
62
|
+
to_hash.keys.sort
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.names
|
66
|
+
to_hash.values.sort
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.find_name_by_abbreviation(abbr)
|
70
|
+
to_hash[abbr.to_s.upcase]
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.find_abbreviation_by_name(name)
|
74
|
+
to_hash.detect{ |k, v| v == name.to_s.capitalize }.first
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.to_hash
|
78
|
+
@hash ||= (
|
79
|
+
h = {}
|
80
|
+
US_STATES.map{ |state| h[state.last] = state.first }
|
81
|
+
h
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'digital_opera/states'
|
3
|
+
|
4
|
+
describe DigitalOpera::States do
|
5
|
+
subject{ DigitalOpera::States }
|
6
|
+
|
7
|
+
describe '#to_collection' do
|
8
|
+
its(:to_collection){ should include ['Alabama', 'AL']}
|
9
|
+
it 'should have 51 records' do
|
10
|
+
subject.to_collection.size.should eq 51
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have a collection of arrays' do
|
14
|
+
subject.to_collection.all?{ |item| item.is_a?(Array) }.should eq true
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have a key matching the name' do
|
18
|
+
subject.to_collection.all?{|item| item.first[0] == item.last[0] }.should be_true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#abbreviations' do
|
23
|
+
its(:abbreviations){ should be_is_a Array }
|
24
|
+
its(:abbreviations){ should include 'AK' }
|
25
|
+
|
26
|
+
it 'should have 51 records' do
|
27
|
+
subject.abbreviations.size.should eq 51
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#names' do
|
32
|
+
its(:names){ should be_is_a Array }
|
33
|
+
its(:names){ should include 'Wyoming' }
|
34
|
+
|
35
|
+
it 'should have 51 records' do
|
36
|
+
subject.names.size.should eq 51
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#find_name_by_abbreviation' do
|
41
|
+
context 'when param is a string' do
|
42
|
+
context 'when is uppercase' do
|
43
|
+
it 'should find state names' do
|
44
|
+
subject.find_name_by_abbreviation('MN').should eq 'Minnesota'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when is downcase' do
|
49
|
+
it 'should find state names' do
|
50
|
+
subject.find_name_by_abbreviation('mn').should eq 'Minnesota'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when is mixed case' do
|
55
|
+
it 'should find state names' do
|
56
|
+
subject.find_name_by_abbreviation('Mn').should eq 'Minnesota'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when param is a symbol' do
|
62
|
+
context 'when is uppercase' do
|
63
|
+
it 'should find state names' do
|
64
|
+
subject.find_name_by_abbreviation(:MN).should eq 'Minnesota'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when is downcase' do
|
69
|
+
it 'should find state names' do
|
70
|
+
subject.find_name_by_abbreviation(:mn).should eq 'Minnesota'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when is mixed case' do
|
75
|
+
it 'should find state names' do
|
76
|
+
subject.find_name_by_abbreviation(:Mn).should eq 'Minnesota'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#find_abbreviation_by_name' do
|
83
|
+
context 'when param is a string' do
|
84
|
+
context 'when is uppercase' do
|
85
|
+
it 'should find state names' do
|
86
|
+
subject.find_abbreviation_by_name('MINNESOTA').should eq 'MN'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when is downcase' do
|
91
|
+
it 'should find state names' do
|
92
|
+
subject.find_abbreviation_by_name('minnesota').should eq 'MN'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when is mixed case' do
|
97
|
+
it 'should find state names' do
|
98
|
+
subject.find_abbreviation_by_name('Minnesota').should eq 'MN'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'when param is a symbol' do
|
104
|
+
context 'when is uppercase' do
|
105
|
+
it 'should find state names' do
|
106
|
+
subject.find_abbreviation_by_name(:MINNESOTA).should eq 'MN'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when is downcase' do
|
111
|
+
it 'should find state names' do
|
112
|
+
subject.find_abbreviation_by_name(:minnesota).should eq 'MN'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when is mixed case' do
|
117
|
+
it 'should find state names' do
|
118
|
+
subject.find_abbreviation_by_name(:Minnesota).should eq 'MN'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#to_hash' do
|
125
|
+
it 'should be a hash' do
|
126
|
+
subject.to_hash.should be_is_a(Hash)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should have a key of abbreviation and a value of name' do
|
130
|
+
subject.to_hash['KY'].should eq 'Kentucky'
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should keys of abbreviations' do
|
134
|
+
subject.to_hash.keys.all?{|key| key.size.should eq 2 }
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should values of names' do
|
138
|
+
subject.to_hash.values.all?{|key| key.size.should > 2 }
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should have a key matching the name' do
|
142
|
+
subject.to_hash.all?{|key, value| key[0] == value[0] }.should be_true
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digital_opera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-03-
|
13
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -291,6 +291,7 @@ files:
|
|
291
291
|
- lib/digital_opera/presenter/base.rb
|
292
292
|
- lib/digital_opera/presenter/concerns/json_serialization.rb
|
293
293
|
- lib/digital_opera/services/s3.rb
|
294
|
+
- lib/digital_opera/states.rb
|
294
295
|
- lib/digital_opera/token.rb
|
295
296
|
- lib/digital_opera/version.rb
|
296
297
|
- spec/dummy/README.rdoc
|
@@ -348,6 +349,7 @@ files:
|
|
348
349
|
- spec/lib/digital_opera/base_extensions/object_spec.rb
|
349
350
|
- spec/lib/digital_opera/presenter/base_spec.rb
|
350
351
|
- spec/lib/digital_opera/services/s3_spec.rb
|
352
|
+
- spec/lib/digital_opera/states_spec.rb
|
351
353
|
- spec/lib/digital_opera/token_spec.rb
|
352
354
|
- spec/spec_helper.rb
|
353
355
|
- spec/support/aws.rb
|
@@ -369,12 +371,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
369
371
|
- - ! '>='
|
370
372
|
- !ruby/object:Gem::Version
|
371
373
|
version: '0'
|
374
|
+
segments:
|
375
|
+
- 0
|
376
|
+
hash: 1226064003626866430
|
372
377
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
373
378
|
none: false
|
374
379
|
requirements:
|
375
380
|
- - ! '>='
|
376
381
|
- !ruby/object:Gem::Version
|
377
382
|
version: '0'
|
383
|
+
segments:
|
384
|
+
- 0
|
385
|
+
hash: 1226064003626866430
|
378
386
|
requirements: []
|
379
387
|
rubyforge_project:
|
380
388
|
rubygems_version: 1.8.23
|
@@ -437,6 +445,7 @@ test_files:
|
|
437
445
|
- spec/lib/digital_opera/base_extensions/object_spec.rb
|
438
446
|
- spec/lib/digital_opera/presenter/base_spec.rb
|
439
447
|
- spec/lib/digital_opera/services/s3_spec.rb
|
448
|
+
- spec/lib/digital_opera/states_spec.rb
|
440
449
|
- spec/lib/digital_opera/token_spec.rb
|
441
450
|
- spec/spec_helper.rb
|
442
451
|
- spec/support/aws.rb
|