Class: Ikku::Scanner

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

Overview

Find one haiku that starts from the 1st node of given nodes.

Constant Summary collapse

DEFAULT_RULE =
[5, 7, 5]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Scanner.



50
51
52
53
54
# File 'lib/ikku.rb', line 50

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

Instance Attribute Details

#countObject

Note:

Pronounciation count



57
58
59
# File 'lib/ikku.rb', line 57

def count
  @count ||= 0
end

Instance Method Details

#scanObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ikku.rb', line 61

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