Class: Ikku::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/ikku/scanner.rb

Overview

Find one set of valid phrases that starts from the 1st node of given nodes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exactly: false, nodes: nil, rule: nil) ⇒ Scanner

Returns a new instance of Scanner.



6
7
8
9
10
# File 'lib/ikku/scanner.rb', line 6

def initialize(exactly: false, nodes: nil, rule: nil)
  @exactly = exactly
  @nodes = nodes
  @rule = rule
end

Instance Attribute Details

#countObject

Note:

Pronunciation count



13
14
15
# File 'lib/ikku/scanner.rb', line 13

def count
  @count ||= 0
end

Instance Method Details

#scanObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ikku/scanner.rb', line 17

def scan
  if has_valid_first_node?
    @nodes.each_with_index do |node, index|
      if consume(node)
        if satisfied?
          return phrases unless @exactly
        end
      else
        return
      end
    end
    phrases if satisfied?
  end
end