extruding-hash 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -54,12 +54,11 @@ Usage
54
54
  -----
55
55
  ```ruby
56
56
  require 'extruding-hash'
57
- data = ExtrudingHash.new
58
- data = { "a1|b1" => [ 1, 2, 3, 5 ], "a3|b3" => [ 2, 3, 5, 8 ],
59
- "a4|b4" => [ 3, 5, 8, 13 ] }
57
+ data = ExtrudingHash.new.set_from_hash({ "a1|b1" => [ 1, 2, 3, 5 ],
58
+ "a3|b3" => [ 2, 3, 5, 8 ], "a4|b4" => [ 3, 5, 8, 13 ] })
60
59
  data << { "a1|b1" => 21, "a2|b2" => 34, "a4|b4" => 55 }
61
60
  data
62
- => {"a1|b1"=>[1, 2, 3, 5, 21], "a2|b2"=>[nil, nil, nil, 34],
61
+ => {"a1|b1"=>[1, 2, 3, 5, 21], "a2|b2"=>[nil, nil, nil, nil, 34],
63
62
  "a3|b3"=>[2, 3, 5, 8, nil], "a4|b4"=>[ 3, 5, 8, 13, 55]}
64
63
  ```
65
64
 
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.platform = Gem::Platform::RUBY
3
3
  s.name = 'extruding-hash'
4
- s.version = '0.9.0'
4
+ s.version = '0.9.1'
5
5
  s.summary = %q{Hash structure for histograms}
6
6
 
7
7
  s.description = %q{Data structure, based on a Hash of Arrays, that
@@ -28,15 +28,17 @@ class ExtrudingHash < Hash
28
28
  # structure, and add nil values to any existing columns that haven't
29
29
  # included the _bins_ of the newly passed-in column.
30
30
  def <<( right )
31
- right.each_key do |key|
32
- self[key] = Array.new if self[key].nil?
33
- end
34
- self.normalize!
31
+ unless right.nil?
32
+ right.each_key do |key|
33
+ self[key] = Array.new if self[key].nil?
34
+ end
35
+ self.normalize!
35
36
 
36
- right.each do |key, value|
37
- self[key] << value
37
+ right.each do |key, value|
38
+ self[key] << value
39
+ end
40
+ self.normalize!
38
41
  end
39
- self.normalize!
40
42
 
41
43
  return self
42
44
  end
@@ -1,7 +1,6 @@
1
1
  require File.expand_path File.join(File.dirname(__FILE__), '../lib/extruding-hash/extruding_hash')
2
2
 
3
- describe ExtrudingHash, "#<<" do
4
-
3
+ describe ExtrudingHash, "#columns" do
5
4
  it "returns the number of columns contained" do
6
5
  test_value = ExtrudingHash.new.set_from_hash( { "a1|b1" => [ 1, 2, 3, 5 ],
7
6
  "a3|b3" => [ 2, 3, 5, 8 ], "a4|b4" => [ 3, 5, 8, 13 ] } )
@@ -9,7 +8,15 @@ describe ExtrudingHash, "#<<" do
9
8
  test_value.columns.should eq(4)
10
9
  end
11
10
 
12
- it "can normalize itself such that all bins' value-arrays are as wide as the widest" do
11
+ it "works with empty structures" do
12
+ test_value = ExtrudingHash.new
13
+
14
+ test_value.columns.should eq(nil)
15
+ end
16
+ end
17
+
18
+ describe ExtrudingHash, "#normalize!" do
19
+ it "can modify itself such that all bins' value-arrays are as wide as the widest" do
13
20
  test_value = ExtrudingHash.new.set_from_hash( { "a1|b1" => [ 1, 2, 3 ],
14
21
  "a3|b3" => [ 2, 3, 5, 8 ] } )
15
22
  test_value.normalize!
@@ -19,6 +26,15 @@ describe ExtrudingHash, "#<<" do
19
26
  test_value.should eq(expected_value)
20
27
  end
21
28
 
29
+ it "works with empty structures" do
30
+ test_value = ExtrudingHash.new
31
+ test_value.normalize!
32
+
33
+ test_value.should eq({ })
34
+ end
35
+ end
36
+
37
+ describe ExtrudingHash, "#<<" do
22
38
  it "adds a column where all bins correspond" do
23
39
  test_value = ExtrudingHash.new.set_from_hash( { "a1|b1" => [ 1, 2, 3, 5 ],
24
40
  "a3|b3" => [ 2, 3, 5, 8 ], "a4|b4" => [ 3, 5, 8, 13 ] } )
@@ -44,4 +60,37 @@ describe ExtrudingHash, "#<<" do
44
60
  test_value.should eq(expected_value)
45
61
  end
46
62
 
63
+ it "works with empty columns" do
64
+ test_value = ExtrudingHash.new.set_from_hash( { "a1|b1" => [ 1, 2, 3, 5 ],
65
+ "a3|b3" => [ 2, 3, 5, 8 ], "a4|b4" => [ 3, 5, 8, 13 ] } )
66
+
67
+ test_value << { }
68
+
69
+ expected_value = { "a1|b1" => [ 1, 2, 3, 5 ],
70
+ "a3|b3" => [ 2, 3, 5, 8 ], "a4|b4" => [ 3, 5, 8, 13 ] }
71
+
72
+ test_value.should eq(expected_value)
73
+ end
74
+
75
+ it "works with nil columns" do
76
+ test_value = ExtrudingHash.new.set_from_hash( { "a1|b1" => [ 1, 2, 3, 5 ],
77
+ "a3|b3" => [ 2, 3, 5, 8 ], "a4|b4" => [ 3, 5, 8, 13 ] } )
78
+
79
+ test_value << nil
80
+
81
+ expected_value = { "a1|b1" => [ 1, 2, 3, 5 ],
82
+ "a3|b3" => [ 2, 3, 5, 8 ], "a4|b4" => [ 3, 5, 8, 13 ] }
83
+
84
+ test_value.should eq(expected_value)
85
+ end
86
+
87
+ it "adds a column to an empty structure" do
88
+ test_value = ExtrudingHash.new
89
+ test_value << { "a1|b1" => 21, "a2|b2" => 34, "a4|b4" => 55 }
90
+
91
+ expected_value = { "a1|b1" => [ 21 ], "a2|b2" => [ 34 ],
92
+ "a4|b4" => [ 55 ] }
93
+
94
+ test_value.should eq(expected_value)
95
+ end
47
96
  end
metadata CHANGED
@@ -1,35 +1,26 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: extruding-hash
3
- version: !ruby/object:Gem::Version
4
- hash: 59
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 9
9
- - 0
10
- version: 0.9.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Andrew Burnheimer
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-10-17 00:00:00 Z
12
+ date: 2012-10-17 00:00:00.000000000Z
19
13
  dependencies: []
14
+ description: ! 'Data structure, based on a Hash of Arrays, that
20
15
 
21
- description: |-
22
- Data structure, based on a Hash of Arrays, that
23
16
  provides a method or two to gather data together in what can be
24
- considered "bins".
17
+
18
+ considered "bins".'
25
19
  email: Andrew_Burnheimer@cable.comcast.com
26
20
  executables: []
27
-
28
21
  extensions: []
29
-
30
22
  extra_rdoc_files: []
31
-
32
- files:
23
+ files:
33
24
  - .gitignore
34
25
  - .rspec
35
26
  - LICENSE
@@ -41,38 +32,30 @@ files:
41
32
  - spec/array_spec.rb
42
33
  - spec/extruding_hash_spec.rb
43
34
  homepage: https://github.com/aburnheimer/extruding-hash
44
- licenses:
35
+ licenses:
45
36
  - CC-BY-3.0
46
37
  post_install_message:
47
38
  rdoc_options: []
48
-
49
- require_paths:
39
+ require_paths:
50
40
  - lib
51
- required_ruby_version: !ruby/object:Gem::Requirement
41
+ required_ruby_version: !ruby/object:Gem::Requirement
52
42
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
60
- required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
48
  none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
- version: "0"
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
69
53
  requirements: []
70
-
71
54
  rubyforge_project:
72
55
  rubygems_version: 1.8.10
73
56
  signing_key:
74
57
  specification_version: 3
75
58
  summary: Hash structure for histograms
76
- test_files:
59
+ test_files:
77
60
  - spec/array_spec.rb
78
61
  - spec/extruding_hash_spec.rb