Class: Elrio::NGramGenerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/elrio/n_gram_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(list, n = 1, offset = 0) ⇒ NGramGenerator

Returns a new instance of NGramGenerator.



5
6
7
8
9
# File 'lib/elrio/n_gram_generator.rb', line 5

def initialize(list, n = 1, offset = 0)
  @offset = offset
  @list = list
  @n = n
end

Instance Method Details

#each {|@list[0, @offset]| ... } ⇒ Object

Yields:

  • (@list[0, @offset])


11
12
13
14
15
16
17
18
19
20
# File 'lib/elrio/n_gram_generator.rb', line 11

def each
  yield @list[0, @offset]

  i = @offset

  while i < @list.size
    yield @list[i, @n]
    i += @n
  end
end