Class: ArrayWordDataSource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wordList, offsetList, size) ⇒ ArrayWordDataSource

Returns a new instance of ArrayWordDataSource.



78
79
80
81
82
83
# File 'lib/data/word_data_source.rb', line 78

def initialize(wordList, offsetList, size)
  @wordList = wordList
  @offsetList = offsetList
  @size = size
  @wordCounts = createWordCounts
end

Instance Attribute Details

#wordCountsObject (readonly)

Returns the value of attribute wordCounts.



76
77
78
# File 'lib/data/word_data_source.rb', line 76

def wordCounts
  @wordCounts
end

Instance Method Details

#each_word(offset = 0) ⇒ Object



100
101
102
103
104
105
# File 'lib/data/word_data_source.rb', line 100

def each_word(offset = 0)
  while ((value = self.valueAt(offset)) != nil) do
    yield value
    offset += 1
  end
end

#valueAt(offset) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/data/word_data_source.rb', line 85

def valueAt(offset)
  if (offset < @size) then
    return @wordList[@offsetList[offset]]
  else
    return nil
  end
end

#verify(word, count) ⇒ Object



93
94
95
96
97
98
# File 'lib/data/word_data_source.rb', line 93

def verify(word, count)
  if (@wordCounts == nil) then
    createWordCounts
  end
  @wordCounts[word] == count
end