symbolmatrix 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
3
+ # - 1.8.7
4
+ # - 1.9.2
5
5
  - 1.9.3
6
- - jruby-18mode
6
+ # - jruby-18mode
7
7
  - jruby-19mode
8
- - rbx-18mode
8
+ # - rbx-18mode
9
9
  - rbx-19mode
10
- - ree
10
+ # - ree
@@ -7,5 +7,5 @@ When /^I parse it$/ do
7
7
  end
8
8
 
9
9
  Then /^I should see \(serialized in yaml\)$/ do |data|
10
- @parsed.to_hash.should include SymbolMatrix.new(data).to_hash
10
+ @parsed.to.hash.should include SymbolMatrix.new(data).to.hash
11
11
  end
@@ -3,7 +3,7 @@ Given /^the SymbolMatrix:$/ do |yaml|
3
3
  end
4
4
 
5
5
  When /^I serialize it$/ do
6
- @serialization = @symbolmatrix.to.serialization
6
+ @serialization = @symbolmatrix.to.smas
7
7
  end
8
8
 
9
9
  Then /^I should get "(.+?)"$/ do |serialization|
@@ -85,6 +85,17 @@ class SymbolMatrix < Hash
85
85
  return result
86
86
  end
87
87
 
88
+ # Merges recursively the passed SymbolMatrix into self
89
+ def recursive_merge! symbolmatrix
90
+ symbolmatrix.each do |key, value|
91
+ if self.has_key? key
92
+ self[key].recursive_merge! value
93
+ else
94
+ self[key] = value
95
+ end
96
+ end
97
+ end
98
+
88
99
  class KeyNotDefinedException < RuntimeError; end
89
100
  class InvalidKeyException < RuntimeError; end
90
101
  end
@@ -1,3 +1,3 @@
1
1
  module Symbolmatrix
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -170,6 +170,57 @@ describe SymbolMatrix do
170
170
  end
171
171
  end
172
172
 
173
+ describe '#recursive_merge!' do
174
+ it 'should merge a symbolmatrix into this' do
175
+ sm = SymbolMatrix.new a: "hola"
176
+ sm.recursive_merge! SymbolMatrix.new b: "chau"
177
+ sm.a.should == "hola"
178
+ sm.b.should == "chau"
179
+ end
180
+
181
+ it 'should merge two symbolmatrices (new values)' do
182
+ sm = SymbolMatrix.new a: "hey"
183
+ sm.recursive_merge! SymbolMatrix.new b: "bye"
184
+ sm.a.should == "hey"
185
+ sm.b.should == "bye"
186
+ end
187
+
188
+ it 'should merge two symbolmatrices (new keys)' do
189
+ sm = SymbolMatrix.new y: "allo"
190
+ sm.recursive_merge! SymbolMatrix.new z: "ciao"
191
+ sm.y.should == "allo"
192
+ sm.z.should == "ciao"
193
+ end
194
+
195
+ it 'should recursively merge this with that (simple)' do
196
+ sm = SymbolMatrix.new another: { b: "aa" }
197
+ sm.recursive_merge! SymbolMatrix.new another: { c: "ee" }
198
+ sm.another.b.should == "aa"
199
+ sm.another.c.should == "ee"
200
+ end
201
+
202
+ it 'should recursively merge this with that (simple)' do
203
+ sm = SymbolMatrix.new distinct: { b: "rr" }
204
+ sm.recursive_merge! SymbolMatrix.new distinct: { c: "gg" }
205
+ sm.distinct.b.should == "rr"
206
+ sm.distinct.c.should == "gg"
207
+ end
208
+
209
+ it 'should recursively merge this with that v2 (simple)' do
210
+ sm = SymbolMatrix.new a: { z: "ee" }
211
+ sm.recursive_merge! SymbolMatrix.new a: { g: "oo" }
212
+ sm.a.z.should == "ee"
213
+ sm.a.g.should == "oo"
214
+ end
215
+
216
+ it 'should recursively merge this with the argument hash' do
217
+ sm = SymbolMatrix.new a: { b: { c: "hola" } }
218
+ sm.recursive_merge! a: { b: { d: "aaa" } }
219
+ sm.a.b.c.should == "hola"
220
+ sm.a.b.d.should == "aaa"
221
+ end
222
+ end
223
+
173
224
  it 'should be a method that calls SymbolMatrix.new with its arguments' do
174
225
  argument = stub 'argument'
175
226
  SymbolMatrix.should_receive(:new).with argument
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: symbolmatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-16 00:00:00.000000000 Z
12
+ date: 2012-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: discoverer