digital_opera 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- digital_opera (0.0.13)
4
+ digital_opera (0.0.14)
5
5
  coffee-rails
6
6
  rails (>= 3.1.0)
7
7
 
data/README.md CHANGED
@@ -8,6 +8,9 @@ independently, and then we thought...maybe someone else would find them useful t
8
8
 
9
9
  If you do find this Gem to be useful, please let us know.
10
10
 
11
+ ### Version 0.0.14
12
+ - Updated [DigitalOpera::States](https://github.com/noiseunion/do-toolbox/wiki/DigitalOpera::States) to accept a mapping parameter to define keys and values
13
+
11
14
  ### Version 0.0.13
12
15
  - 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
16
 
@@ -54,8 +54,34 @@ module DigitalOpera
54
54
  ['Wyoming', 'WY']
55
55
  ]
56
56
 
57
- def self.to_collection
58
- @collection ||= US_STATES.sort{|a, b| a.first <=> b.first }
57
+ def self.to_collection(mapping={})
58
+ @collection = (
59
+ states = US_STATES
60
+
61
+ if mapping[:key].present? || mapping[:value].present?
62
+ states =US_STATES.map do |state|
63
+ key = state.last
64
+ value = state.first
65
+
66
+ if mapping[:value] == :abbr
67
+ value = state.last
68
+ elsif mapping[:value] == :name
69
+ value = state.first
70
+ end
71
+
72
+ if mapping[:key] == :name
73
+ key = state.first
74
+ elsif mapping[:key] == :abbr
75
+ key = state.last
76
+ end
77
+
78
+ [value, key]
79
+
80
+ end
81
+ end
82
+
83
+ states.sort{|a, b| a.first <=> b.first }
84
+ )
59
85
  end
60
86
 
61
87
  def self.abbreviations
@@ -1,3 +1,3 @@
1
1
  module DigitalOpera
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
@@ -17,6 +17,62 @@ describe DigitalOpera::States do
17
17
  it 'should have a key matching the name' do
18
18
  subject.to_collection.all?{|item| item.first[0] == item.last[0] }.should be_true
19
19
  end
20
+
21
+ context 'when mapping is supplied' do
22
+ subject{ DigitalOpera::States.to_collection({key: :abbr, value: :name}) }
23
+
24
+ it 'should not raise error' do
25
+ expect{ subject }.to_not raise_error
26
+ end
27
+
28
+ it 'should have abbreviation as key' do
29
+ subject.first.last.should eq 'AL'
30
+ end
31
+
32
+ it 'should have name as key' do
33
+ subject = DigitalOpera::States.to_collection({key: :name})
34
+ subject.first.last.should eq 'Alabama'
35
+ end
36
+
37
+ it 'should have abbreviation as key' do
38
+ subject = DigitalOpera::States.to_collection({key: :abbr})
39
+ subject.first.last.should eq 'AL'
40
+ end
41
+
42
+ it 'should have name as value' do
43
+ subject = DigitalOpera::States.to_collection({value: :name})
44
+ subject.first.first.should eq 'Alabama'
45
+ end
46
+
47
+ it 'should have abbreviation as value' do
48
+ subject = DigitalOpera::States.to_collection({value: :abbr})
49
+ subject.first.first.should eq 'AK'
50
+ end
51
+
52
+ it 'should have name as key and name as value' do
53
+ subject = DigitalOpera::States.to_collection({key: :name, value: :name})
54
+ subject.first.first.should eq 'Alabama'
55
+ subject.first.last.should eq 'Alabama'
56
+ end
57
+
58
+ it 'should have abbreviation as key and abbreviation as value' do
59
+ subject = DigitalOpera::States.to_collection({key: :abbr, value: :abbr})
60
+ subject.first.first.should eq 'AK'
61
+ subject.first.last.should eq 'AK'
62
+ end
63
+
64
+ it 'should have name as key and abbreviation as value' do
65
+ subject = DigitalOpera::States.to_collection({key: :name, value: :abbr})
66
+ subject.first.first.should eq 'AK'
67
+ subject.first.last.should eq 'Alaska'
68
+ end
69
+
70
+ it 'should have abbreviation as key and name as value' do
71
+ subject = DigitalOpera::States.to_collection({key: :abbr, value: :name})
72
+ subject.first.first.should eq 'Alabama'
73
+ subject.first.last.should eq 'AL'
74
+ end
75
+ end
20
76
  end
21
77
 
22
78
  describe '#abbreviations' do
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.13
4
+ version: 0.0.14
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-11 00:00:00.000000000 Z
13
+ date: 2014-03-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -373,7 +373,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
373
373
  version: '0'
374
374
  segments:
375
375
  - 0
376
- hash: 1226064003626866430
376
+ hash: 2192845350802676624
377
377
  required_rubygems_version: !ruby/object:Gem::Requirement
378
378
  none: false
379
379
  requirements:
@@ -382,7 +382,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
382
382
  version: '0'
383
383
  segments:
384
384
  - 0
385
- hash: 1226064003626866430
385
+ hash: 2192845350802676624
386
386
  requirements: []
387
387
  rubyforge_project:
388
388
  rubygems_version: 1.8.23