Class: Milkode::WideMatcher
- Inherits:
-
Object
- Object
- Milkode::WideMatcher
- Defined in:
- lib/milkode/common/wide_matcher.rb
Instance Attribute Summary collapse
-
#num_max ⇒ Object
readonly
Returns the value of attribute num_max.
Class Method Summary collapse
Instance Method Summary collapse
- #add_line_matchs(index, matches) ⇒ Object
-
#initialize(num_max) ⇒ WideMatcher
constructor
A new instance of WideMatcher.
- #linenum ⇒ Object
- #match? ⇒ Boolean
- #match_lines ⇒ Object
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_max ⇒ Object (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 |
#linenum ⇒ Object
27 28 29 |
# File 'lib/milkode/common/wide_matcher.rb', line 27 def linenum @container.size end |
#match? ⇒ 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_lines ⇒ Object
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 |