Class: WordSearch::WordBank
- Inherits:
-
Array
- Object
- Array
- WordSearch::WordBank
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/word_search/word_bank.rb
Instance Method Summary collapse
-
#initialize(file) ⇒ WordBank
constructor
A new instance of WordBank.
- #longest_length ⇒ Object
- #longest_words ⇒ Object
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_length ⇒ Object
22 23 24 |
# File 'lib/word_search/word_bank.rb', line 22 def longest_length @longest ||= collect(&:length).max.to_i end |
#longest_words ⇒ Object
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 |