Class: WordDataSource
Instance Attribute Summary collapse
#startOffset
Instance Method Summary
collapse
#each_with_index, #extendWith, #has_terminator?, #nextDataSourceValueAt, #valueSequence
Constructor Details
#initialize(filePath, regex = "/[^a-z0-9\-\s]/i") ⇒ WordDataSource
Returns a new instance of WordDataSource.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# 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
|
Instance Attribute Details
#numberWordsInFile ⇒ Object
Returns the value of attribute numberWordsInFile.
4
5
6
|
# File 'lib/data/word_data_source.rb', line 4
def numberWordsInFile
@numberWordsInFile
end
|
#words ⇒ Object
Returns the value of attribute words.
4
5
6
|
# File 'lib/data/word_data_source.rb', line 4
def words
@words
end
|
Instance Method Details
#numberValues ⇒ Object
21
22
23
|
# File 'lib/data/word_data_source.rb', line 21
def numberValues
return @words.length
end
|
#preprocessLine(line) ⇒ Object
38
39
40
|
# File 'lib/data/word_data_source.rb', line 38
def preprocessLine(line)
line.downcase.gsub(@regex, ' ')
end
|
#process(line) ⇒ Object
25
26
27
28
|
# File 'lib/data/word_data_source.rb', line 25
def process(line)
line = self.preprocessLine(line)
return self.processData(line.split)
end
|
#processData(data) ⇒ Object
30
31
32
33
34
35
36
|
# 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) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
|
# 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) ⇒ Object
42
43
44
45
|
# File 'lib/data/word_data_source.rb', line 42
def valueAt(offset)
return @words[offset] if (offset < @numberWordsInFile)
return nil
end
|