Class: WordSearch::WordBank

Inherits:
Array
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/word_search/word_bank.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ WordBank

Returns a new instance of WordBank.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/word_search/word_bank.rb', line 9

def initialize(file)
  return invalid_file unless valid_file?(file)
  words = []

  CSV.foreach(file) do |row|
    row.each do |word|
      words << word.strip.downcase if word.strip.length > 1
    end
  end

  super words.uniq
end

Instance Method Details

#longest_lengthObject



22
23
24
# File 'lib/word_search/word_bank.rb', line 22

def longest_length
  @longest ||= collect(&:length).max.to_i
end

#longest_wordsObject



26
27
28
29
30
# File 'lib/word_search/word_bank.rb', line 26

def longest_words
  select do |word|
    word.length == longest_length
  end
end