motion-map 0.0.1 → 0.0.3

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.
@@ -1,3 +1,3 @@
1
1
  module MotionMap
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  module MapHelper
2
2
  def new_int_map(n = 1024)
3
- Map.new.tap do |m|
3
+ MotionMap::Map.new.tap do |m|
4
4
  n.times{|i| m[i.to_s] = i}
5
5
  end
6
6
  end
@@ -1,29 +1,29 @@
1
- describe Map do
1
+ describe MotionMap::Map do
2
2
  extend MapHelper
3
3
 
4
4
  describe 'constructor' do
5
5
  it 'supports bare constructor' do
6
- map = Map.new
6
+ map = MotionMap::Map.new
7
7
  map .count.should == 0
8
8
  end
9
-
9
+
10
10
  it 'can take a hash' do
11
- map = Map.new( {} )
11
+ map = MotionMap::Map.new( {} )
12
12
  map.count.should == 0
13
13
  end
14
14
 
15
15
  it 'can take an empty array' do
16
16
  array = []
17
- map = Map.new( array )
17
+ map = MotionMap::Map.new( array )
18
18
  map.count.should == 0
19
- map = Map.new( *array )
19
+ map = MotionMap::Map.new( *array )
20
20
  map.count.should == 0
21
21
  end
22
22
 
23
23
  it 'deals with nil correctly' do
24
- map = Map.new( nil )
24
+ map = MotionMap::Map.new( nil )
25
25
  map.count.should == 0
26
- map = Map.new( false )
26
+ map = MotionMap::Map.new( false )
27
27
  map.count.should == 0
28
28
  end
29
29
 
@@ -36,9 +36,9 @@ describe Map do
36
36
  expectations = [1, 2, 2]
37
37
  i = 0
38
38
  arrays.each do |array|
39
- map = Map.new(array)
39
+ map = MotionMap::Map.new(array)
40
40
  map.count.should == expectations[i]
41
- map = Map.new(*array)
41
+ map = MotionMap::Map.new(*array)
42
42
  map.count.should == expectations[i]
43
43
  i += 1
44
44
  end
@@ -52,9 +52,9 @@ describe Map do
52
52
  [:key, :val]
53
53
  ]
54
54
  list.each do |args|
55
- map = Map[*args]
56
- map.class.should == Map
57
- Map.new(*args).should == map
55
+ map = MotionMap::Map[*args]
56
+ map.class.should == MotionMap::Map
57
+ MotionMap::Map.new(*args).should == map
58
58
  end
59
59
  end
60
60
  end
@@ -82,7 +82,7 @@ describe Map do
82
82
 
83
83
  describe 'accessors' do
84
84
  it 'Maps string/symbol indifferent for simple look-ups' do
85
- map = Map.new
85
+ map = MotionMap::Map.new
86
86
  map[:k] = :v
87
87
  map['a'] = 'b'
88
88
  map[:k].should == :v
@@ -92,8 +92,7 @@ describe Map do
92
92
  end
93
93
 
94
94
  it 'Maps string/symbol indifferent for recursive look-ups' do
95
- map = Map(:a => {:b => {:c => 42}})
96
-
95
+ map = MotionMap::Map[:a => {:b => {:c => 42}}]
97
96
  map[:a].should == {:b => {:c => 42}}
98
97
  map[:a][:b][:c].should == 42
99
98
  map['a'][:b][:c].should == 42
@@ -103,15 +102,15 @@ describe Map do
103
102
  map[:a]['b']['c'].should == 42
104
103
  map[:a][:b]['c'].should == 42
105
104
  map['a'][:b]['c'].should == 42
106
-
107
- map = Map[:a => [{:b => 42}]]
105
+
106
+ map = MotionMap::Map[:a => [{:b => 42}]]
108
107
  map['a'].class.should == Array
109
- map['a'][0].class.should == Map
108
+ map['a'][0].class.should == MotionMap::Map
110
109
  map['a'][0]['b'].should == 42
111
-
112
- map = Map(:a => [ {:b => 42}, [{:c => 'forty-two'}] ])
110
+
111
+ map = MotionMap::Map[:a => [ {:b => 42}, [{:c => 'forty-two'}] ]]
113
112
  map['a'].class.should == Array
114
- map['a'][0].class.should == Map
113
+ map['a'][0].class.should == MotionMap::Map
115
114
  map['a'][1].class.should == Array
116
115
  map['a'][0]['b'].should == 42
117
116
  map['a'][1][0]['c'].should == 'forty-two'
@@ -120,7 +119,7 @@ describe Map do
120
119
 
121
120
  describe 'shift' do
122
121
  it 'supports shift like a good ordered container' do
123
- map = Map.new
122
+ map = MotionMap::Map.new
124
123
  10.times do |i|
125
124
  key, val = i.to_s, i
126
125
  map.unshift(key, val)
@@ -129,7 +128,7 @@ describe Map do
129
128
  map.values.first.to_s.should == val.to_s
130
129
  end
131
130
 
132
- map = Map.new
131
+ map = MotionMap::Map.new
133
132
  args = []
134
133
  10.times do |i|
135
134
  key, val = i.to_s, i
@@ -153,14 +152,14 @@ describe Map do
153
152
  end
154
153
 
155
154
  it 'supports inheritence without cycles' do
156
- c = Class.new(Map){}
155
+ c = Class.new(MotionMap::Map){}
157
156
  o = c.new
158
- Map.should === o
157
+ MotionMap::Map.should === o
159
158
  end
160
159
 
161
160
  it 'captures equality correctly' do
162
- a = Map.new
163
- b = Map.new
161
+ a = MotionMap::Map.new
162
+ b = MotionMap::Map.new
164
163
  a.should == b
165
164
  a.should != 42
166
165
  b[:k] = :v
@@ -170,19 +169,19 @@ describe Map do
170
169
 
171
170
  describe 'keys as methods' do
172
171
  it 'works with simple usage' do
173
- a = Map.new( k: :v)
172
+ a = MotionMap::Map.new( k: :v)
174
173
  a.k.should == :v
175
174
  end
176
175
 
177
176
  it 'works with complexusage' do
178
- a = Map.new( k: {a: {b: 10}} )
177
+ a = MotionMap::Map.new( k: {a: {b: 10}} )
179
178
  a.k.a.b.should == 10
180
179
  end
181
180
  end
182
181
 
183
182
  describe 'subclassing' do
184
183
  it 'insures subclassing and clobbering initialize does not kill nested coersion' do
185
- c = Class.new(Map){ def initialize(arg) end }
184
+ c = Class.new(MotionMap::Map){ def initialize(arg) end }
186
185
  o = c.new(42)
187
186
  o.class.should == c
188
187
  o.update(:k => {:a => :b})
@@ -190,26 +189,26 @@ describe Map do
190
189
  end
191
190
 
192
191
  it 'ensures that subclassing does not kill class level coersion' do
193
- c = Class.new(Map){ }
194
- o = c.for(Map.new)
192
+ c = Class.new(MotionMap::Map){ }
193
+ o = c.for(MotionMap::Map.new)
195
194
  o.class.should == c
196
195
 
197
196
  d = Class.new(c)
198
- o = d.for(Map.new)
197
+ o = d.for(MotionMap::Map.new)
199
198
  o.class.should == d
200
199
  end
201
200
  end
202
201
 
203
202
  describe '#to_list' do
204
203
  it 'insures Maps can be converted to lists with numeric indexes' do
205
- m = Map[0, :a, 1, :b, 2, :c]
204
+ m = MotionMap::Map[0, :a, 1, :b, 2, :c]
206
205
  m.to_list.should == [:a, :b, :c]
207
206
  end
208
207
  end
209
208
 
210
209
  describe 'method_missing' do
211
210
  it 'ensures method_missing hacks allow setting values, but not getting them until they are set' do
212
- m = Map.new
211
+ m = MotionMap::Map.new
213
212
  (m.missing rescue $!).class.should == NoMethodError
214
213
  m.missing = :val
215
214
  m[:missing].should == :val
@@ -217,7 +216,7 @@ describe Map do
217
216
  end
218
217
 
219
218
  it 'ensures method_missing hacks have sane respond_to? semantics' do
220
- m = Map.new
219
+ m = MotionMap::Map.new
221
220
  m.respond_to?(:missing).should == false
222
221
  m.respond_to?(:missing=).should == true
223
222
  m.missing = :val
@@ -226,7 +225,7 @@ describe Map do
226
225
  end
227
226
 
228
227
  it 'ensures method missing with a block delegatets to fetch' do
229
- m = Map.new
228
+ m = MotionMap::Map.new
230
229
  m.missing{ :val }.should == :val
231
230
  m.has_key?(:key).should == false
232
231
  end
@@ -234,34 +233,34 @@ describe Map do
234
233
 
235
234
  describe 'compound keys' do
236
235
  it 'Maps support compound key/val setting' do
237
- m = Map.new
236
+ m = MotionMap::Map.new
238
237
  m.set(:a, :b, :c, 42)
239
238
  m.get(:a, :b, :c).should == 42
240
239
 
241
- m = Map.new
240
+ m = MotionMap::Map.new
242
241
  m.set([:a, :b, :c], 42)
243
242
  m.get(:a, :b, :c) == 42
244
243
 
245
- m = Map.new
244
+ m = MotionMap::Map.new
246
245
  m.set([:a, :b, :c] => 42)
247
246
  m.get(:a, :b, :c) == 42
248
247
 
249
- m = Map.new
248
+ m = MotionMap::Map.new
250
249
  m.set([:x, :y, :z] => 42.0, [:A, 2] => 'forty-two')
251
250
  m[:A].class.should == Array
252
251
  m[:A].size.should == 3
253
252
  m[:A][2].should == 'forty-two'
254
- m[:x][:y].class.should == Map
253
+ m[:x][:y].class.should == MotionMap::Map
255
254
  m[:x][:y][:z].should == 42.0
256
255
 
257
- Map.new.tap{|m| m.set}.should =~ {}
258
- Map.new.tap{|m| m.set({})} =~ {}
256
+ MotionMap::Map.new.tap{|m| m.set}.should =~ {}
257
+ MotionMap::Map.new.tap{|m| m.set({})} =~ {}
259
258
  end
260
259
  end
261
260
 
262
261
  describe '#get' do
263
262
  it 'supports providing a default value in a block' do
264
- m = Map.new
263
+ m = MotionMap::Map.new
265
264
  m.set(:a, :b, :c, 42)
266
265
  m.set(:z, 1)
267
266
 
@@ -269,12 +268,12 @@ describe Map do
269
268
  m.get(:z){2}.should == 1
270
269
  m.get(:a, :b, :d){1}.should == 1
271
270
  m.get(:a, :b, :c){1}.should == 42
272
- m.get(:a, :b){1}.should == Map({:c => 42})
271
+ m.get(:a, :b){1}.should == MotionMap::Map[{:c => 42}]
273
272
  m.get(:a, :aa){1}.should == 1
274
273
  end
275
274
 
276
275
  it 'ensures setting a sub-container does not eff up the container values' do
277
- m = Map.new
276
+ m = MotionMap::Map.new
278
277
  m.set(:array => [0,1,2])
279
278
  m.get(:array, 0).should == 0
280
279
  m.get(:array, 1).should == 1
@@ -289,21 +288,21 @@ describe Map do
289
288
 
290
289
  describe 'merging' do
291
290
  it 'ensures #apply selectively merges non-nil values' do
292
- m = Map.new(:array => [0, 1], :hash => {:a => false, :b => nil, :c => 42})
293
- defaults = Map.new(:array => [nil, nil, 2], :hash => {:b => true})
291
+ m = MotionMap::Map.new(:array => [0, 1], :hash => {:a => false, :b => nil, :c => 42})
292
+ defaults = MotionMap::Map.new(:array => [nil, nil, 2], :hash => {:b => true})
294
293
 
295
294
  m.apply(defaults)
296
295
  m[:array].should == [0,1,2]
297
296
  m[:hash].should =~ {:a => false, :b => true, :c => 42}
298
297
 
299
- m = Map.new
298
+ m = MotionMap::Map.new
300
299
  m.apply :key => [{:key => :val}]
301
300
  m[:key].class.should == Array
302
- m[:key][0].class.should == Map
301
+ m[:key][0].class.should == MotionMap::Map
303
302
  end
304
303
 
305
304
  it 'ensures #add overlays the leaves of one hash onto another without nuking branches' do
306
- m = Map.new
305
+ m = MotionMap::Map.new
307
306
 
308
307
  m.add(
309
308
  :comments => [
@@ -319,15 +318,15 @@ describe Map do
319
318
  [{"body"=>"a", "title"=>"teh title", "description"=>"description"},
320
319
  {"body"=>"b", "description"=>"description"}]}
321
320
 
322
- m = Map.new
321
+ m = MotionMap::Map.new
323
322
  m.add(
324
323
  [:a, :b, :c] => 42,
325
324
  [:a, :b] => {:d => 42.0}
326
325
  )
327
326
  m.should =~ {"a"=>{"b"=>{"c"=>42, "d"=>42.0}}}
328
327
 
329
- Map.new.tap{|m| m.add}.should =~ {}
330
- Map.new.tap{|m| m.add({})}.should =~ {}
328
+ MotionMap::Map.new.tap{|m| m.add}.should =~ {}
329
+ MotionMap::Map.new.tap{|m| m.add({})}.should =~ {}
331
330
  end
332
331
 
333
332
  it 'ensures that Map.combine is teh sweet' do
@@ -336,14 +335,14 @@ describe Map do
336
335
  [{:a => {:b => 42}}, {:a => {:c => 42.0, :d => [1]}}] => {"a"=>{"b"=>42, "d"=>[1], "c"=>42.0}},
337
336
  [{:a => {:b => 42}}, {:a => {:c => 42.0, :d => {0=>1}}}] => {"a"=>{"b"=>42, "d"=>{0=>1}, "c"=>42.0}}
338
337
  }.each do |args, expected|
339
- Map.combine(*args).should =~ expected
338
+ MotionMap::Map.combine(*args).should =~ expected
340
339
  end
341
340
  end
342
341
  end
343
342
 
344
343
  describe 'traversal' do
345
344
  it 'supports depth_first_each' do
346
- m = Map.new
345
+ m = MotionMap::Map.new
347
346
  prefix = %w[ a b c ]
348
347
  keys = []
349
348
  n = 0.42
@@ -355,8 +354,8 @@ describe Map do
355
354
  m.set(key => val)
356
355
  n *= 10
357
356
  end
358
- m.get(:a).class.should == Map
359
- m.get(:a, :b).class.should == Map
357
+ m.get(:a).class.should == MotionMap::Map
358
+ m.get(:a, :b).class.should == MotionMap::Map
360
359
  m.get(:a, :b, :c).class.should == Array
361
360
 
362
361
  n = 0.42
@@ -370,12 +369,12 @@ describe Map do
370
369
  it 'ensures #each_pair works on arrays' do
371
370
  each = []
372
371
  array = %w( a b c )
373
- Map.each_pair(array){|k,v| each.push(k,v)}
372
+ MotionMap::Map.each_pair(array){|k,v| each.push(k,v)}
374
373
  each.should == ['a', 'b', 'c', nil]
375
374
  end
376
375
 
377
376
  it 'supports breath_first_each' do
378
- m = Map[
377
+ m = MotionMap::Map[
379
378
  'hash' , {'x' => 'y'},
380
379
  'nested hash' , {'nested' => {'a' => 'b'}},
381
380
  'array' , [0, 1, 2],
@@ -384,7 +383,7 @@ describe Map do
384
383
  ]
385
384
 
386
385
  accum = []
387
- m.breadth_first_each(Map){|k, v| accum.push([k, v])}
386
+ m.breadth_first_each(MotionMap::Map){|k, v| accum.push([k, v])}
388
387
  expected =
389
388
  [
390
389
  [["hash"], {"x"=>"y"}],
@@ -413,7 +412,7 @@ describe Map do
413
412
 
414
413
  describe '#contains' do
415
414
  it 'handles needle-in-a-haystack like #contains? method' do
416
- haystack = Map[
415
+ haystack = MotionMap::Map[
417
416
  'hash' , {'x' => 'y'},
418
417
  'nested hash' , {'nested' => {'a' => 'b'}},
419
418
  'array' , [0, 1, 2],
@@ -442,21 +441,21 @@ describe Map do
442
441
  end
443
442
 
444
443
  it 'ensures #blank? method that is sane' do
445
- m = Map.new(:a => 0, :b => ' ', :c => '', :d => {}, :e => [], :f => false)
444
+ m = MotionMap::Map.new(:a => 0, :b => ' ', :c => '', :d => {}, :e => [], :f => false)
446
445
  m.each do |key, val|
447
446
  m.blank?(key).should == true
448
447
  end
449
448
 
450
- m = Map.new(:a => 1, :b => '_', :d => {:k=>:v}, :e => [42], :f => true)
449
+ m = MotionMap::Map.new(:a => 1, :b => '_', :d => {:k=>:v}, :e => [42], :f => true)
451
450
  m.each do |key, val|
452
451
  m.blank?(key).should == false
453
452
  end
454
- Map.new.blank?.should == true
453
+ MotionMap::Map.new.blank?.should == true
455
454
  end
456
455
 
457
456
  it 'ensures self referential Maps do not make #inspect puke' do
458
- a = Map.new
459
- b = Map.new
457
+ a = MotionMap::Map.new
458
+ b = MotionMap::Map.new
460
459
 
461
460
  b[:a] = a
462
461
  a[:b] = b
@@ -471,7 +470,7 @@ describe Map do
471
470
  end
472
471
 
473
472
  it 'has a clever little rm operator' do
474
- m = Map.new
473
+ m = MotionMap::Map.new
475
474
  m.set :a, :b, 42
476
475
  m.set :x, :y, 42
477
476
  m.set :x, :z, 42
@@ -501,7 +500,7 @@ describe Map do
501
500
  end
502
501
 
503
502
  it 'Maps a clever little question method' do
504
- m = Map.new
503
+ m = MotionMap::Map.new
505
504
  m.set(:a, :b, :c, 42)
506
505
  m.set([:x, :y, :z] => 42.0, [:A, 2] => 'forty-two')
507
506
 
@@ -517,5 +516,5 @@ describe Map do
517
516
  m.y?.should == false
518
517
 
519
518
  m.A?.should == true
520
- end
519
+ end
521
520
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernand Galiana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-19 00:00:00.000000000 Z
11
+ date: 2013-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  prerelease: false