Class: FrequencyAnalyser::Counter
- Inherits:
-
Struct
- Object
- Struct
- FrequencyAnalyser::Counter
- Defined in:
- lib/frequency_analyser/counter.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain
1 2 3 |
# File 'lib/frequency_analyser/counter.rb', line 1 def domain @domain end |
Class Method Details
.count(text) ⇒ Object
3 4 5 |
# File 'lib/frequency_analyser/counter.rb', line 3 def self.count(text) new('a'..'z').count(text.dup) end |
Instance Method Details
#count(text) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/frequency_analyser/counter.rb', line 7 def count(text) text.downcase! domain.inject(Hash.new(0)) do |hash, c| count = text.count(c) hash[c] = count unless count.zero? hash end end |