class ScrabbleScore::Letters
Constants
- TILE_VALUES
Attributes
word[R]
Public Class Methods
cleanse(word)
click to toggle source
# File lib/scrabble_score/letters.rb, line 35 def self.cleanse(word) word.downcase.gsub(/[^a-z]/, '') end
new(word)
click to toggle source
# File lib/scrabble_score/letters.rb, line 13 def initialize(word) @word = Letters.cleanse(word) end
Public Instance Methods
permutations()
click to toggle source
# File lib/scrabble_score/letters.rb, line 17 def permutations permutation_array = [] letter_array = @word.split(//) (2..letter_array.size).each do |length| letter_array.permutation(length).each do |perm| permutation_array << perm.join end end permutation_array.uniq end
score()
click to toggle source
# File lib/scrabble_score/letters.rb, line 29 def score score = 0 @word.downcase.each_char { |ch| score += TILE_VALUES[ch] } score end