Class: WordScramble::LetterFrequency

Inherits:
Object
  • Object
show all
Defined in:
lib/word_scramble/letter_frequency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ LetterFrequency

Returns a new instance of LetterFrequency.



4
5
6
7
8
9
10
11
12
# File 'lib/word_scramble/letter_frequency.rb', line 4

def initialize(str)
  @length = str.length
  @frequency_hash = {}

  str.downcase.each_char do |c| 
    @frequency_hash[c] ||= 0
    @frequency_hash[c] += 1
  end
end

Instance Attribute Details

#frequency_hashObject (readonly)

Returns the value of attribute frequency_hash.



2
3
4
# File 'lib/word_scramble/letter_frequency.rb', line 2

def frequency_hash
  @frequency_hash
end

#lengthObject (readonly)

Returns the value of attribute length.



2
3
4
# File 'lib/word_scramble/letter_frequency.rb', line 2

def length
  @length
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
# File 'lib/word_scramble/letter_frequency.rb', line 14

def ==(other)
  other.is_a?(WordScramble::LetterFrequency) and other.frequency_hash == @frequency_hash
end