Class: FlickrCollage::Dictionary

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

Constant Summary

DICT_FILE =
"/usr/share/dict/words"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Dictionary

Returns a new instance of Dictionary



22
23
24
25
26
27
# File 'lib/FlickrCollage.rb', line 22

def initialize(opts = {})
  opts[:file] ||= DICT_FILE
  @words = File.read(opts[:file]).lines.select do |line|
    (4..9).cover?(line.strip.size)
  end
end

Instance Attribute Details

#wordsArray

Returns All words at dictionary file

Returns:

  • (Array)

    All words at dictionary file



20
21
22
# File 'lib/FlickrCollage.rb', line 20

def words
  @words
end

Instance Method Details

#get_wordString

Get random word from Dictionary file

Returns:

  • (String)

    random word



32
33
34
# File 'lib/FlickrCollage.rb', line 32

def get_word
  @words.sample.strip
end