trick_bag 0.49.0 → 0.50.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c735881db9b16262fde9e1753bbf19a2d3f09a2
4
- data.tar.gz: bae4754d55eb643fdd1d0ecfb66533b0bd984c13
3
+ metadata.gz: 18fca0df6bf55045308d1addceafea1793c14b87
4
+ data.tar.gz: 37c89c74b67277d29d959d10a0d17636c6347269
5
5
  SHA512:
6
- metadata.gz: 2ca095d4e271a8e963a6d1bba1541699e0bfc33ee7dc1db9adee2dc6dc1669a582144dd55b24ebd3f15d62a1e7960ad382df7ddf9b1b48ae9ab3e90afa359a62
7
- data.tar.gz: a1100d716519313fe9158210264217cebc99283924cf7fcd612714d1ae1563f7e0f2b4296d3505701d8f8c4d756d0c340b5589d3fa337e588f7219bee741779e
6
+ metadata.gz: fa4fa5ddde0bca6c34ef27af74122b1ae1b669597b135f674b0f8e3dfac812a0d69576cea742ca2fe27ef5473cc1895ff5f046f1da0c36ec7d1104cfb2e5365c
7
+ data.tar.gz: 377ec62488029e12b522af9e8cc0ec7ee49bdd54028cc85c916b9d4da5c3f7b10ad99ef7e67714c3e17217401a8f6476d7213b056f6e9886f8ab74bd542ac88f
data/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.50.0
2
+
3
+ * On MultiCounter, fixed percent_of_total_hash, added fraction_of_total_hash.
4
+
5
+
1
6
  ## v0.49.0
2
7
 
3
8
  * Corrected name from from_array to from_enumerable.
@@ -15,6 +15,7 @@ class MultiCounter
15
15
  @counts = Hash.new(0)
16
16
  end
17
17
 
18
+ # Creates an instance and iterates over the enumberable, processing all its items.
18
19
  def self.from_enumerable(values, name = '')
19
20
  m_counter = MultiCounter.new(name)
20
21
  values.each { |value| m_counter.increment(value) }
@@ -51,13 +52,28 @@ class MultiCounter
51
52
  @counts.values.inject(0, &:+)
52
53
  end
53
54
 
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
55
+ # Private internal method for use by percent_of_total_hash
56
+ # and fraction_of_total_hash.
57
+ # @param mode :percent or :fraction
58
+ def of_total_hash(mode = :percent)
59
+ raise "bad mode: #{mode}" unless [:percent, :fraction].include?(mode)
57
60
  total = total_count
58
61
  keys.each_with_object({}) do |key, ptotal_hash|
59
- ptotal_hash[key] = Float(self[key]) / total
62
+ value = Float(self[key]) / total
63
+ value *= 100 if mode == :percent
64
+ ptotal_hash[key] = value
60
65
  end
66
+ end; private :of_total_hash
67
+
68
+ # Returns a hash whose keys are the multicounter's keys and whose values
69
+ # are the percent of total of the values corresponding to those keys.
70
+ def percent_of_total_hash
71
+ of_total_hash(:percent)
72
+ end
73
+ # Returns a hash whose keys are the multicounter's keys and whose values
74
+ # are the fraction of total of the values corresponding to those keys.
75
+ def fraction_of_total_hash
76
+ of_total_hash(:fraction)
61
77
  end
62
78
 
63
79
  # Creates a hash whose keys are this counter's keys, and whose values are
@@ -1,3 +1,3 @@
1
1
  module TrickBag
2
- VERSION = "0.49.0"
2
+ VERSION = "0.50.0"
3
3
  end
@@ -38,6 +38,13 @@ module Numeric
38
38
 
39
39
  specify 'percent_of_total_hash is correctly calculated' do
40
40
  ptotal_hash = MultiCounter.from_enumerable(sample_data).percent_of_total_hash
41
+ expect(ptotal_hash['Open']).to eq(60.0)
42
+ expect(ptotal_hash['Closed']).to eq(20.0)
43
+ expect(ptotal_hash['New']).to eq(20.0)
44
+ end
45
+
46
+ specify 'fraction_of_total_hash is correctly calculated' do
47
+ ptotal_hash = MultiCounter.from_enumerable(sample_data).fraction_of_total_hash
41
48
  expect(ptotal_hash['Open']).to eq(0.6)
42
49
  expect(ptotal_hash['Closed']).to eq(0.2)
43
50
  expect(ptotal_hash['New']).to eq(0.2)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trick_bag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.49.0
4
+ version: 0.50.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Bennett