ms_pivot 0.1.2 → 0.1.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.
data/README.md CHANGED
@@ -42,7 +42,8 @@ A little gem to help you pivot your arrays.
42
42
  - MSPivot::AVG
43
43
  - MSPivot::MIN
44
44
  - MSPivot::MAX
45
- - MSPivot::APPEND (builds an array)
45
+ - MSPivot::APPEND (builds an array of items)
46
+ - MSPivot::SINGLE (returns a single item, and throws an exception otherwise)
46
47
 
47
48
  - Or specify your own measure function
48
49
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -27,6 +27,11 @@ module MsPivot
27
27
  current_value << new_value
28
28
  end
29
29
 
30
+ SINGLE = Measure.new do |current_value, new_value|
31
+ raise "More than one value found for SINGLE measure" unless current_value.nil?
32
+ new_value
33
+ end
34
+
30
35
  SUM = Measure.new do |current_value, new_value|
31
36
  current_value ||= 0
32
37
  current_value + new_value
data/ms_pivot.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ms_pivot}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aisha Fenton"]
12
- s.date = %q{2010-12-16}
12
+ s.date = %q{2010-12-17}
13
13
  s.description = %q{A little gem to help you pivot your arrays}
14
14
  s.email = %q{aisha.fenton@visfleet.com}
15
15
  s.extra_rdoc_files = [
data/spec/measure_spec.rb CHANGED
@@ -2,7 +2,7 @@ require 'lib/ms_pivot'
2
2
 
3
3
  describe MsPivot::Measure do
4
4
 
5
- it "supports a SUM measure" do
5
+ it "sums up the values" do
6
6
  orig_array = [
7
7
  ["ProductA", "NZ", 1],
8
8
  ["ProductA", "NZ", 2],
@@ -17,7 +17,7 @@ describe MsPivot::Measure do
17
17
  ]
18
18
  end
19
19
 
20
- it "supports a MIN measure" do
20
+ it "returns the minimum value" do
21
21
  orig_array = [
22
22
  ["ProductA", "NZ", -100],
23
23
  ["ProductA", "NZ", 0],
@@ -33,7 +33,7 @@ describe MsPivot::Measure do
33
33
  ]
34
34
  end
35
35
 
36
- it "supports a MAX measure" do
36
+ it "returns the maximum value" do
37
37
  orig_array = [
38
38
  ["ProductA", "NZ", -2],
39
39
  ["ProductA", "NZ", 2],
@@ -49,7 +49,7 @@ describe MsPivot::Measure do
49
49
  ]
50
50
  end
51
51
 
52
- it "supports a COUNT measure" do
52
+ it "returns a count of how many items where measured" do
53
53
 
54
54
  orig_array = [
55
55
  ["ProductA", "NZ", "z"],
@@ -67,7 +67,7 @@ describe MsPivot::Measure do
67
67
  ]
68
68
  end
69
69
 
70
- it "supports a AVG measure" do
70
+ it "returns the average value" do
71
71
  orig_array = [
72
72
  ["ProductA", "NZ", 2],
73
73
  ["ProductA", "NZ", 3],
@@ -84,7 +84,7 @@ describe MsPivot::Measure do
84
84
  ]
85
85
  end
86
86
 
87
- it "supports an APPEND measure" do
87
+ it "returns an array containing all items measured" do
88
88
  orig_array = [
89
89
  ["ProductA", "NZ", "x"],
90
90
  ["ProductA", "NZ", "y"],
@@ -97,4 +97,27 @@ describe MsPivot::Measure do
97
97
  ]
98
98
  end
99
99
 
100
+ it "returns a single item" do
101
+ orig_array = [
102
+ ["ProductA", "NZ", "x"],
103
+ ["ProductA", "AU", "y"],
104
+ ]
105
+
106
+ pv = MsPivot::Table.new(orig_array, 0, 1, MsPivot::SINGLE)
107
+
108
+ pv.to_a.should == [
109
+ ["ProductA", ["y"], ["x"]],
110
+ ]
111
+ end
112
+
113
+ it "throws an exception if the SINGLE measure finds more than one item" do
114
+ orig_array = [
115
+ ["ProductA", "NZ", "x"],
116
+ ["ProductA", "NZ", "y"],
117
+ ]
118
+
119
+ expect { MsPivot::Table.new(orig_array, 0, 1, MsPivot::SINGLE) }.to raise_error
120
+
121
+ end
122
+
100
123
  end
data/spec/table_spec.rb CHANGED
@@ -8,7 +8,7 @@ describe MsPivot::Table, "with a single measure" do
8
8
  ["ProductA", "US", 2],
9
9
  ["ProductB", "NZ", 3],
10
10
  ]
11
- MsPivot::Table.new(orig_array, 0, 1, MsPivot::SUM)
11
+ MsPivot::Table.new(orig_array, 0, 1, MsPivot::SINGLE)
12
12
  end
13
13
 
14
14
  its(:row_headers) { should == ["ProductA", "ProductB"] }
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Aisha Fenton
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-16 00:00:00 +13:00
17
+ date: 2010-12-17 00:00:00 +13:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency