trick_bag 0.48.0 → 0.49.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/RELEASE_NOTES.md +6 -0
- data/lib/trick_bag/numeric/multi_counter.rb +46 -1
- data/lib/trick_bag/version.rb +1 -1
- data/spec/trick_bag/numeric/multi_counter_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c735881db9b16262fde9e1753bbf19a2d3f09a2
|
4
|
+
data.tar.gz: bae4754d55eb643fdd1d0ecfb66533b0bd984c13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ca095d4e271a8e963a6d1bba1541699e0bfc33ee7dc1db9adee2dc6dc1669a582144dd55b24ebd3f15d62a1e7960ad382df7ddf9b1b48ae9ab3e90afa359a62
|
7
|
+
data.tar.gz: a1100d716519313fe9158210264217cebc99283924cf7fcd612714d1ae1563f7e0f2b4296d3505701d8f8c4d756d0c340b5589d3fa337e588f7219bee741779e
|
data/RELEASE_NOTES.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
## v0.49.0
|
2
|
+
|
3
|
+
* Corrected name from from_array to from_enumerable.
|
4
|
+
|
5
|
+
|
1
6
|
## v0.48.0
|
2
7
|
|
3
8
|
* Add TrickBag::Numeric::MultiCounter#total_count and #percent_of_total_hash.
|
4
9
|
|
10
|
+
|
5
11
|
## v0.47.0
|
6
12
|
|
7
13
|
* Remove array_as_multiline_string; it's too similar to array.join("\n").
|
@@ -15,7 +15,7 @@ class MultiCounter
|
|
15
15
|
@counts = Hash.new(0)
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.
|
18
|
+
def self.from_enumerable(values, name = '')
|
19
19
|
m_counter = MultiCounter.new(name)
|
20
20
|
values.each { |value| m_counter.increment(value) }
|
21
21
|
m_counter
|
@@ -74,3 +74,48 @@ class MultiCounter
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
77
|
+
|
78
|
+
|
79
|
+
=begin
|
80
|
+
|
81
|
+
Here is a sample script that exercises some of this class' features:
|
82
|
+
|
83
|
+
#!/usr/bin/env ruby
|
84
|
+
|
85
|
+
require 'trick_bag'
|
86
|
+
require 'awesome_print'
|
87
|
+
|
88
|
+
data = %w(Open New Open Closed Open New Closed Open Open Open)
|
89
|
+
m_counter = TrickBag::Numeric::MultiCounter.from_enumerable(data, 'Status for Issue #123')
|
90
|
+
puts "\nMultiCounter hash:"
|
91
|
+
ap m_counter.to_hash
|
92
|
+
|
93
|
+
puts "\nNumber Open:"
|
94
|
+
puts m_counter['Open']
|
95
|
+
|
96
|
+
pc_totals = m_counter.percent_of_total_hash
|
97
|
+
puts "\nPercents of Total:"
|
98
|
+
ap pc_totals
|
99
|
+
|
100
|
+
|
101
|
+
# Output is:
|
102
|
+
#
|
103
|
+
# MultiCounter hash:
|
104
|
+
# {
|
105
|
+
# "Open" => 6,
|
106
|
+
# "New" => 2,
|
107
|
+
# "Closed" => 2
|
108
|
+
# }
|
109
|
+
#
|
110
|
+
# Number Open:
|
111
|
+
# 6
|
112
|
+
#
|
113
|
+
# Percents of Total:
|
114
|
+
# {
|
115
|
+
# "Open" => 0.6,
|
116
|
+
# "New" => 0.2,
|
117
|
+
# "Closed" => 0.2
|
118
|
+
# }
|
119
|
+
|
120
|
+
=end
|
121
|
+
|
data/lib/trick_bag/version.rb
CHANGED
@@ -31,13 +31,13 @@ module Numeric
|
|
31
31
|
end
|
32
32
|
|
33
33
|
specify 'creating from an array works correctly' do
|
34
|
-
m_counter = MultiCounter.
|
34
|
+
m_counter = MultiCounter.from_enumerable(sample_data)
|
35
35
|
expect(m_counter.total_count).to eq(10)
|
36
36
|
expect(m_counter['Open']).to eq(6)
|
37
37
|
end
|
38
38
|
|
39
39
|
specify 'percent_of_total_hash is correctly calculated' do
|
40
|
-
ptotal_hash = MultiCounter.
|
40
|
+
ptotal_hash = MultiCounter.from_enumerable(sample_data).percent_of_total_hash
|
41
41
|
expect(ptotal_hash['Open']).to eq(0.6)
|
42
42
|
expect(ptotal_hash['Closed']).to eq(0.2)
|
43
43
|
expect(ptotal_hash['New']).to eq(0.2)
|