frequency_analyser 1.2.1 → 1.2.2
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.
@@ -9,7 +9,7 @@ class FrequencyAnalyser::Aggregator < Struct.new(:counter, :aggregation)
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def aggregate(*files)
|
12
|
-
files =
|
12
|
+
files = coerce(files)
|
13
13
|
files.each do |file|
|
14
14
|
file.each_line do |line|
|
15
15
|
aggregation << counter.count(line)
|
@@ -23,4 +23,8 @@ class FrequencyAnalyser::Aggregator < Struct.new(:counter, :aggregation)
|
|
23
23
|
FrequencyAnalyser
|
24
24
|
end
|
25
25
|
|
26
|
+
def coerce(files)
|
27
|
+
[files].flatten
|
28
|
+
end
|
29
|
+
|
26
30
|
end
|
@@ -1,37 +1,35 @@
|
|
1
|
-
class FrequencyAnalyser::Modifier
|
1
|
+
class FrequencyAnalyser::Modifier < Struct.new(:aggregation)
|
2
2
|
|
3
3
|
def self.modify(aggregation, mode)
|
4
|
-
new.modify(
|
4
|
+
new(aggregation).modify(mode)
|
5
5
|
end
|
6
6
|
|
7
|
-
def modify(
|
7
|
+
def modify(mode)
|
8
8
|
case mode
|
9
9
|
when :probability
|
10
|
-
probability
|
10
|
+
probability
|
11
11
|
when :percentage
|
12
|
-
percentage
|
12
|
+
percentage
|
13
13
|
else
|
14
14
|
aggregation
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
19
|
-
def probability
|
20
|
-
sum = sum(aggregation)
|
19
|
+
def probability
|
21
20
|
aggregation.inject(aggregation) do |hash, (k, v)|
|
22
21
|
hash.merge!(k => v.to_f / sum)
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
def percentage
|
27
|
-
sum = sum(aggregation)
|
25
|
+
def percentage
|
28
26
|
aggregation.inject(aggregation) do |hash, (k, v)|
|
29
27
|
hash.merge!(k => v.to_f / sum * 100)
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
33
|
-
def sum
|
34
|
-
aggregation.values.inject(:+)
|
31
|
+
def sum
|
32
|
+
@sum ||= aggregation.values.inject(:+)
|
35
33
|
end
|
36
34
|
|
37
35
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frequency_analyser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 2
|
10
|
+
version: 1.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Christopher Patuzzo
|