Class: ArrayWordDataSource
- Inherits:
-
Object
- Object
- ArrayWordDataSource
- Defined in:
- lib/data/word_data_source.rb
Instance Attribute Summary collapse
-
#wordCounts ⇒ Object
readonly
Returns the value of attribute wordCounts.
Instance Method Summary collapse
- #each_word(offset = 0) ⇒ Object
-
#initialize(wordList, offsetList, size) ⇒ ArrayWordDataSource
constructor
A new instance of ArrayWordDataSource.
- #valueAt(offset) ⇒ Object
- #verify(word, count) ⇒ Object
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
#wordCounts ⇒ Object (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 |