Class: Milkode::WideMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/milkode/common/wide_matcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num_max) ⇒ WideMatcher

Returns a new instance of WideMatcher.



22
23
24
25
# File 'lib/milkode/common/wide_matcher.rb', line 22

def initialize(num_max)
  @num_max   = num_max
  @container = []
end

Instance Attribute Details

#num_maxObject (readonly)

Returns the value of attribute num_max.



12
13
14
# File 'lib/milkode/common/wide_matcher.rb', line 12

def num_max
  @num_max
end

Class Method Details

.create(num_max) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/milkode/common/wide_matcher.rb', line 14

def self.create(num_max)
  if num_max == 0
    WideMatcherZero.new
  else
    WideMatcher.new(num_max)
  end
end

Instance Method Details

#add_line_matchs(index, matches) ⇒ Object



31
32
33
34
35
36
# File 'lib/milkode/common/wide_matcher.rb', line 31

def add_line_matchs(index, matches)
  @last_index = index
  @container.shift if linenum >= @num_max
  @container << matches
  # p @container
end

#linenumObject



27
28
29
# File 'lib/milkode/common/wide_matcher.rb', line 27

def linenum
  @container.size
end

#match?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'lib/milkode/common/wide_matcher.rb', line 38

def match?
  @container.reduce(Array.new(@container.first.size)) {|result, matches|
    matches.each_with_index do |m, i|
      result[i] |= m
    end
    result
  }.all?
end

#match_linesObject



47
48
49
50
51
52
53
54
55
# File 'lib/milkode/common/wide_matcher.rb', line 47

def match_lines
  index = @last_index - @container.size + 1
  @container.reduce([]) do |result, matches|
    m = matches.compact
    result << MatchLineResult.new(index, m) unless m.empty?
    index += 1
    result
  end
end