textstat 0.1.7 → 0.1.8

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: 61ef6dcf0e938af4c3c30ad4b45c3241f10ffc01e4d63e566a74d993b57309ac
4
+ data.tar.gz: 20f6412df8d5a8658d4113ddb48e808697b7e1489ba5acb4fae9d97346393acd
5
5
  SHA512:
6
- metadata.gz: cea3d3fddb63789e61c94e7d1c88f97c73bc0265f8ac0ccfc904487b7eed508661161a415a1adfdade6573472034b9bb81d2a61f0eb12038ad8ae270afdde29f
7
- data.tar.gz: f4c548b9e2450fcde82b19ee8a52a1d8631f706f1d7126cc6ba0644483cff3713e0bba7698d51816d5e6081b480f376e31dc69ba69b7940f4cb229bb9a10681d
6
+ metadata.gz: ef7dee598e3db4c26e2e305f464fbebf6b3757429a72ae66b887ab7f068a34a0d2b6c2e5c52771b2c342e8c06d2ec9a69fa1d60065eaa37b3ccf76eb232f647d
7
+ data.tar.gz: 5ca1f7c6dcb11a81457b87339ab153ac95125542378875fd451c9ba58659925fc018d38af4bbc61149cb5f8f53765f67363029d8eb698ad80effa969d7ecbbeb
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