textstat 0.1.7 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36293590e0400cf26cb711c90af89f85ac89e9a6f72db7ce244a508a547c90ff
4
- data.tar.gz: ce4c7990bed0de64bc483356798794651326477fb2e2bdb1da37abed7c1e9e63
3
+ metadata.gz: 88480347f6e6a1c232dc30a7ee14e4cf98154936e28a9fb2d1aaa6fe0f176aed
4
+ data.tar.gz: bce6f0fc8222542dba6a8e0961d20fd3b68313571769f1cd7c7dd13c5fc28926
5
5
  SHA512:
6
- metadata.gz: cea3d3fddb63789e61c94e7d1c88f97c73bc0265f8ac0ccfc904487b7eed508661161a415a1adfdade6573472034b9bb81d2a61f0eb12038ad8ae270afdde29f
7
- data.tar.gz: f4c548b9e2450fcde82b19ee8a52a1d8631f706f1d7126cc6ba0644483cff3713e0bba7698d51816d5e6081b480f376e31dc69ba69b7940f4cb229bb9a10681d
6
+ metadata.gz: d3490d4920b60d1a6defa19eb80a2918bd92fafcf265b8f55aae50f617da88becaeba562a73fe20b91020f0ed21a2e912556c6cbb8314bc5f8210a8debcbe82c
7
+ data.tar.gz: f4a7c7aba924df2005da79cf48a675e6d1f2655d56debe90590e748b56fdc1bccffa80ce245ba644d5fe0e5119d5b66159946569a05f715579bfaaa8185edb61
data/lib/counter.rb CHANGED
@@ -1,37 +1,37 @@
1
- class Counter < Hash
2
- def initialize(other = nil)
3
- super(0)
4
- other.each { |e| self[e] += 1 } if other.is_a? Array
5
- other.each { |k, v| self[k] = v } if other.is_a? Hash
6
- other.each_char { |e| self[e] += 1 } if other.is_a? String
7
- end
8
-
9
- def +(rhs)
10
- raise TypeError, "cannot add #{rhs.class} to a Counter" unless rhs.is_a? Counter
11
-
12
- result = Counter.new(self)
13
- rhs.each { |k, v| result[k] += v }
14
- result
15
- end
16
-
17
- def -(rhs)
18
- raise TypeError, "cannot subtract #{rhs.class} to a Counter" unless rhs.is_a? Counter
19
-
20
- result = Counter.new(self)
21
- rhs.each { |k, v| result[k] -= v }
22
- result
23
- end
24
-
25
- def most_common(n = nil)
26
- s = sort_by { |_k, v| -v }
27
- n ? s.take(n) : s
28
- end
29
-
30
- def to_s
31
- "Counter(#{super})"
32
- end
33
-
34
- def inspect
35
- to_s
36
- end
37
- end
1
+ class Counter < Hash
2
+ def initialize(other = nil)
3
+ super(0)
4
+ other.each { |e| self[e] += 1 } if other.is_a? Array
5
+ other.each { |k, v| self[k] = v } if other.is_a? Hash
6
+ other.each_char { |e| self[e] += 1 } if other.is_a? String
7
+ end
8
+
9
+ def +(rhs)
10
+ raise TypeError, "cannot add #{rhs.class} to a Counter" unless rhs.is_a? Counter
11
+
12
+ result = Counter.new(self)
13
+ rhs.each { |k, v| result[k] += v }
14
+ result
15
+ end
16
+
17
+ def -(rhs)
18
+ raise TypeError, "cannot subtract #{rhs.class} to a Counter" unless rhs.is_a? Counter
19
+
20
+ result = Counter.new(self)
21
+ rhs.each { |k, v| result[k] -= v }
22
+ result
23
+ end
24
+
25
+ def most_common(n = nil)
26
+ s = sort_by { |_k, v| -v }
27
+ n ? s.take(n) : s
28
+ end
29
+
30
+ def to_s
31
+ "Counter(#{super})"
32
+ end
33
+
34
+ def inspect
35
+ to_s
36
+ end
37
+ end