trick_bag 0.47.0 → 0.48.0
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.
- checksums.yaml +4 -4
- data/RELEASE_NOTES.md +4 -0
- data/lib/trick_bag/numeric/multi_counter.rb +20 -0
- data/lib/trick_bag/version.rb +1 -1
- data/spec/trick_bag/numeric/multi_counter_spec.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5b83787b4b4a7182fb18c9cbcd6eb7d3fcf6a18b
|
|
4
|
+
data.tar.gz: 8b0ff5d556e5d0da614f680672a31553484458b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 049f3157a32ece02aa9b5d55aecc639de6463d2c1f7738577be6840291232a7efdb391ae49e47ee6a013cf805e41e139cab502abc500912b1a03d9f1a61797f0
|
|
7
|
+
data.tar.gz: 89bbbc2ded12adca468ad8e3298363d62ba29b29bb53f6823ffe409cc28ddfd9fe822aa993bf724d139d943df4db49ac3892feb1f573847d99f12a5646afeef8
|
data/RELEASE_NOTES.md
CHANGED
|
@@ -15,6 +15,12 @@ class MultiCounter
|
|
|
15
15
|
@counts = Hash.new(0)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def self.from_array(values, name = '')
|
|
19
|
+
m_counter = MultiCounter.new(name)
|
|
20
|
+
values.each { |value| m_counter.increment(value) }
|
|
21
|
+
m_counter
|
|
22
|
+
end
|
|
23
|
+
|
|
18
24
|
# Adds keys in the passed enumerable to this counter.
|
|
19
25
|
def add_keys(keys)
|
|
20
26
|
keys.each { |key| @counts[key] = 0 }
|
|
@@ -40,6 +46,20 @@ class MultiCounter
|
|
|
40
46
|
keys.include?(key)
|
|
41
47
|
end
|
|
42
48
|
|
|
49
|
+
# Returns the total of all counts.
|
|
50
|
+
def total_count
|
|
51
|
+
@counts.values.inject(0, &:+)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Returns a hash whose keys are the multicounter's keys and whose values
|
|
55
|
+
# are the percent of total of the values corresponding to those keys.
|
|
56
|
+
def percent_of_total_hash
|
|
57
|
+
total = total_count
|
|
58
|
+
keys.each_with_object({}) do |key, ptotal_hash|
|
|
59
|
+
ptotal_hash[key] = Float(self[key]) / total
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
43
63
|
# Creates a hash whose keys are this counter's keys, and whose values are
|
|
44
64
|
# their corresponding values.
|
|
45
65
|
def to_hash
|
data/lib/trick_bag/version.rb
CHANGED
|
@@ -8,6 +8,8 @@ module Numeric
|
|
|
8
8
|
|
|
9
9
|
subject { MultiCounter.new }
|
|
10
10
|
|
|
11
|
+
let(:sample_data) { %w(Open New Open Closed Open New Closed Open Open Open) }
|
|
12
|
+
|
|
11
13
|
it "should instantiate" do
|
|
12
14
|
expect(-> { subject }).not_to raise_error
|
|
13
15
|
end
|
|
@@ -23,6 +25,24 @@ module Numeric
|
|
|
23
25
|
expect(subject.keys.sort).to eq(keys.sort)
|
|
24
26
|
end
|
|
25
27
|
|
|
28
|
+
specify 'total_count is correct' do
|
|
29
|
+
sample_data.each { |datum| subject.increment(datum) }
|
|
30
|
+
expect(subject.total_count).to eq(10)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
specify 'creating from an array works correctly' do
|
|
34
|
+
m_counter = MultiCounter.from_array(sample_data)
|
|
35
|
+
expect(m_counter.total_count).to eq(10)
|
|
36
|
+
expect(m_counter['Open']).to eq(6)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
specify 'percent_of_total_hash is correctly calculated' do
|
|
40
|
+
ptotal_hash = MultiCounter.from_array(sample_data).percent_of_total_hash
|
|
41
|
+
expect(ptotal_hash['Open']).to eq(0.6)
|
|
42
|
+
expect(ptotal_hash['Closed']).to eq(0.2)
|
|
43
|
+
expect(ptotal_hash['New']).to eq(0.2)
|
|
44
|
+
end
|
|
26
45
|
end
|
|
27
46
|
end
|
|
28
47
|
end
|
|
48
|
+
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: trick_bag
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.48.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Keith Bennett
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-07-
|
|
11
|
+
date: 2014-07-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: os
|