frequency_analyser 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +14 -0
  2. data/lib/frequency_analyser/base.rb +10 -5
  3. metadata +3 -3
data/README.md CHANGED
@@ -21,3 +21,17 @@ FrequencyAnalyser.analyse(file)
21
21
  'y'=>11849, 'z'=>213
22
22
  }
23
23
  ```
24
+
25
+ You can analyse strings too:
26
+
27
+ ```ruby
28
+ FrequencyAnalyser.analyse('Hello, world!')
29
+ #=> { 'd'=>1, 'e'=>1, 'h'=>1, 'l'=>3, 'o'=>2, 'r'=>1, 'w'=>1 }
30
+ ```
31
+
32
+ And collections of things:
33
+
34
+ ```ruby
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}
37
+ ```
@@ -1,13 +1,18 @@
1
1
  class FrequencyAnalyser < Struct.new(:counter, :aggregation)
2
2
 
3
- def self.analyse(file)
4
- new(Counter, Aggregation.new).analyse(file)
3
+ def self.analyse(*files)
4
+ new(Counter, Aggregation.new).analyse(*files)
5
5
  end
6
6
 
7
- def analyse(file)
8
- file.each_line do |line|
9
- aggregation << counter.count(line)
7
+ def analyse(*files)
8
+ files = *files.flatten
9
+
10
+ files.each do |file|
11
+ file.each_line do |line|
12
+ aggregation << counter.count(line)
13
+ end
10
14
  end
15
+
11
16
  aggregation
12
17
  end
13
18
 
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: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 1
10
- version: 0.0.1
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christopher Patuzzo