class TripPhrase::WordType

Attributes

type[R]

Public Class Methods

new(type) click to toggle source
# File lib/trip_phrase/word_type.rb, line 6
def initialize(type)
  @type = type
end

Public Instance Methods

[](index) click to toggle source
# File lib/trip_phrase/word_type.rb, line 18
def [](index)
  words[index % length]
end
length() click to toggle source
# File lib/trip_phrase/word_type.rb, line 14
def length
  @length ||= words.length
end
words() click to toggle source
# File lib/trip_phrase/word_type.rb, line 10
def words
  @words ||= words_from_file
end

Protected Instance Methods

file_path() click to toggle source
# File lib/trip_phrase/word_type.rb, line 35
def file_path
  File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', 'data', "#{type}.txt")
end
words_from_file() click to toggle source
# File lib/trip_phrase/word_type.rb, line 24
def words_from_file
  words = []
  IO.foreach(file_path) do |word|
    word.strip!
    if word =~ /^[a-z]+$/ and word.length > 1
      words << word
    end
  end
  words
end