frequency_analyser 1.0.0 → 1.1.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.
- data/README.md +14 -1
- data/lib/frequency_analyser/base.rb +5 -1
- data/lib/frequency_analyser/counter.rb +3 -3
- metadata +3 -3
data/README.md
CHANGED
@@ -33,5 +33,18 @@ And collections of things:
|
|
33
33
|
|
34
34
|
```ruby
|
35
35
|
FrequencyAnalyser.analyse('foo', File.new('bar'), StringIO.new('baz'), ['q', 'u', 'x'])
|
36
|
-
#=> {'a'=>2, 'b'=>2, 'f'=>1, 'o'=>2, 'q'=>1, 'r'=>1, 'u'=>1, 'x'=>1, 'z'=>1}
|
36
|
+
#=> { 'a'=>2, 'b'=>2, 'f'=>1, 'o'=>2, 'q'=>1, 'r'=>1, 'u'=>1, 'x'=>1, 'z'=>1 }
|
37
|
+
```
|
38
|
+
|
39
|
+
## Counting other things
|
40
|
+
|
41
|
+
By defeault, Frequency Analyser counts alphabetic characters. You can
|
42
|
+
change this by instantiating your own counter:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
counter = FrequencyAnalyser::Counter.new(%w(1 3 5 !))
|
46
|
+
analyser = FrequencyAnalyser.new(counter)
|
47
|
+
|
48
|
+
analyser.analyse('!12321!')
|
49
|
+
#=> { '!'=>2, '1'=>2, '3'=>1 }
|
37
50
|
```
|
@@ -1,7 +1,11 @@
|
|
1
1
|
class FrequencyAnalyser < Struct.new(:counter, :aggregation)
|
2
2
|
|
3
|
+
def initialize(counter = Counter, aggregation = Aggregation.new)
|
4
|
+
super
|
5
|
+
end
|
6
|
+
|
3
7
|
def self.analyse(*files)
|
4
|
-
new
|
8
|
+
new.analyse(*files)
|
5
9
|
end
|
6
10
|
|
7
11
|
def analyse(*files)
|
@@ -1,12 +1,12 @@
|
|
1
|
-
class FrequencyAnalyser::Counter
|
1
|
+
class FrequencyAnalyser::Counter < Struct.new(:domain)
|
2
2
|
|
3
3
|
def self.count(text)
|
4
|
-
new.count(text.dup)
|
4
|
+
new('a'..'z').count(text.dup)
|
5
5
|
end
|
6
6
|
|
7
7
|
def count(text)
|
8
8
|
text.downcase!
|
9
|
-
|
9
|
+
domain.inject(Hash.new(0)) do |hash, c|
|
10
10
|
count = text.count(c)
|
11
11
|
hash[c] = count unless count.zero?
|
12
12
|
hash
|
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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Christopher Patuzzo
|