class WordDataSource

Attributes

numberWordsInFile[R]
words[R]

Public Class Methods

new(filePath, regex = "/[^a-z0-9\-\s]/i") click to toggle source
# File lib/data/word_data_source.rb, line 6
def initialize(filePath, regex = "/[^a-z0-9\-\s]/i")
  @filePath = filePath
  @words = []
  @regex = regex
  File.open(filePath, "r") do |file|
    file.each_line do |line|
      line.chomp!
      if (self.process(line)) then
        break
      end
    end
  end
  @numberWordsInFile = @words.length
end

Public Instance Methods

numberValues() click to toggle source
# File lib/data/word_data_source.rb, line 21
def numberValues
  return @words.length
end
preprocessLine(line) click to toggle source
# File lib/data/word_data_source.rb, line 38
def preprocessLine(line)
  line.downcase.gsub(@regex, ' ')
end
process(line) click to toggle source
# File lib/data/word_data_source.rb, line 25
def process(line)
  line = self.preprocessLine(line)
  return self.processData(line.split)
end
processData(data) click to toggle source
# File lib/data/word_data_source.rb, line 30
def processData(data)
  data.each do |word|
    word = word.chomp(",")
    @words << word
  end
  return false
end
toString(startOffset, endOffset) click to toggle source
# File lib/data/word_data_source.rb, line 47
def toString(startOffset, endOffset)
  if (endOffset == -1) then
    result = "#{@words[startOffset]} ..*"
  else
    result = ""
    (startOffset..endOffset).each do |offset|
      result += "#{@words[offset]} "
    end
  end
  result
end
valueAt(offset) click to toggle source
# File lib/data/word_data_source.rb, line 42
def valueAt(offset)
  return @words[offset] if (offset < @numberWordsInFile)
  return nil
end