stacker_bee 2.1.1.pre295 → 2.1.1.pre300

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWI0NTZiOWVmNjBiMmZiZTgwYTMyMWZiY2E1NTY4MThjY2M4MjBkMw==
4
+ MmVlMzQ3YjA3NzRjYTlmNjBkNWI5N2QyNGNjOWJhYWUzZDQyZWExZA==
5
5
  data.tar.gz: !binary |-
6
- ZmJkMjZjYmUyOGE2YmRlZGYxOThlNjI4NTRlYWIxOGY2NTc5YzA5ZQ==
6
+ ZWM2NzM4NzUwNTAxYTEwZjNlN2VmMjFmM2JjMzA0MTVlNTQ0NTUzOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODg5YzdjODA1YTg5MjQ1NTJiNjdkOTdmMTM0ZmY4YWI3NDMxNjJkMjRhYTU5
10
- OTA2ZmE2OGFhYjUzZTcyOTEwYTYyYzMxOTU1OThkMjliZTBkN2MwNjE0ZDI0
11
- ZjQ0NzkwNmE2N2EyNTJhNDFjMTc5OTdmOGQxYmRhMTkwNjJmY2E=
9
+ OTJkM2RlNjRlOTcyZWQyZGNjNjVkYjM0YzJhYjQ3YmMyNGFkOWU4MTEyMzg0
10
+ MzcxNWZmYjMzNzYzMDM4YzM5YzBiYWIyZjUyMzE2YTg2NmQ1ZjZmMWEzMmYw
11
+ YTExMDk4YjQzOGFkMWU1NTlkMDc3MmQ4MWQ2Y2IxOWJiN2FjZDU=
12
12
  data.tar.gz: !binary |-
13
- Y2Q5MWU2MjVlZWU4NTc3ODAzOTU1MDM4NDA4MTE3NzEyYWQyMjFlZjJlZjc4
14
- Mjc4YjAzMmZjZjczNWYzZTVlYTM3MTRlOWRhMzE5NzI1NjlmODJkOTQ3ZDc2
15
- ZTg5MDdmYjM1MDYyZjRhOGJhNGVkOTg4MjhmZGE4ZmI1NTk4NzE=
13
+ OTQ0ZTRhMjc2Njg0NjM3ZjdmMjdmZGRiZDJjMjcyM2I1NDM5MzM4M2IzMDUy
14
+ NjQxMDhlYjZlODAxYTlhZGU4ZTVkZjE1ZmE5YTAyNDI0YzEwYTIzN2I5ZmZj
15
+ ZDA2MTM4OTgzNzcyMzIzMDJhNTM4Zjg4NWU0NzZhMWRjMjhhZDM=
@@ -12,8 +12,11 @@ module StackerBee
12
12
  :flatten, :invert, :keys, :key, :merge, :rassoc, :to_a, :to_h, :to_hash
13
13
  ]
14
14
 
15
- def initialize(hash = {})
15
+ def initialize(hash = {}, preferred_keys = [])
16
16
  @hash = {}
17
+
18
+ save_preferred_keys preferred_keys
19
+
17
20
  hash.each_pair do |key, value|
18
21
  @hash[convert_key(key)] = convert_value(value)
19
22
  end
@@ -78,7 +81,27 @@ module StackerBee
78
81
  end
79
82
 
80
83
  def convert_key(key)
81
- key.is_a?(Numeric) ? key : uncase(key)
84
+ if key.is_a?(Numeric)
85
+ key
86
+ elsif preferred_key_format?(key)
87
+ preferred_key_format(key)
88
+ else
89
+ uncase(key)
90
+ end
91
+ end
92
+
93
+ def save_preferred_keys(keys)
94
+ @preferred_keys = keys.each_with_object({}) do |key, mapping|
95
+ mapping[uncase(key)] = key
96
+ end
97
+ end
98
+
99
+ def preferred_key_format?(key)
100
+ @preferred_keys.key?(uncase(key))
101
+ end
102
+
103
+ def preferred_key_format(key)
104
+ @preferred_keys[uncase(key)]
82
105
  end
83
106
 
84
107
  def convert_value(value)
@@ -3,7 +3,7 @@ shared_examples_for 'a Rash' do |mapping|
3
3
  end
4
4
 
5
5
  describe StackerBee::Rash do
6
- subject { rash }
6
+ subject(:rash) { described_class.new(hash) }
7
7
 
8
8
  let(:wiz) { [{ 'aB_C' => 'abc' }, { 'X_yZ' => 'xyz' }] }
9
9
  let(:ziz) do
@@ -28,7 +28,6 @@ describe StackerBee::Rash do
28
28
  end
29
29
  end
30
30
  let(:dissimilar_hash) { hash.dup.tap { |loud| loud.delete 'foo' } }
31
- let(:rash) { described_class.new(hash) }
32
31
 
33
32
  it { is_expected.to include 'FOO' }
34
33
 
@@ -82,4 +81,21 @@ describe StackerBee::Rash do
82
81
  subject { rash.values_at 'FOO', 'WIZ', 'WRONG' }
83
82
  it { is_expected.to eq ['foo', wiz, nil] }
84
83
  end
84
+
85
+ describe 'with preferred keys' do
86
+ subject { described_class.new(hash, preferred_keys) }
87
+ let(:preferred_keys) { [:foo, 'BAR', :b_a_z] }
88
+ let(:hash) do
89
+ {
90
+ f_o_o: 'foo',
91
+ ba_r: 'bar',
92
+ baz: 'baz',
93
+ Ot_her: 'other'
94
+ }
95
+ end
96
+
97
+ it 'is stored as preferred if mentioned, otherwise as uncased' do
98
+ expect(subject.keys).to match_array [:foo, 'BAR', :b_a_z, 'other']
99
+ end
100
+ end
85
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stacker_bee
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1.pre295
4
+ version: 2.1.1.pre300
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sterndale
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-09 00:00:00.000000000 Z
12
+ date: 2014-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday