Class: OrExpression
- Inherits:
-
CompoundExpression
- Object
- Expression
- CompoundExpression
- OrExpression
- Defined in:
- lib/glark/match/or.rb
Overview
A collection of expressions, evaluated as ‘or’.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from CompoundExpression
Attributes inherited from Expression
Instance Method Summary collapse
- #end_position ⇒ Object
- #evaluate(line, lnum, file, formatter) ⇒ Object
- #explain(level = 0) ⇒ Object
- #inspect ⇒ Object
Methods inherited from CompoundExpression
#==, #initialize, #reset_file, #start_position
Methods inherited from Expression
#add_match, #initialize, #process, #reset_file, #start_position, #to_s
Constructor Details
This class inherits a constructor from CompoundExpression
Instance Method Details
#end_position ⇒ Object
32 33 34 |
# File 'lib/glark/match/or.rb', line 32 def end_position @last_end end |
#evaluate(line, lnum, file, formatter) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/glark/match/or.rb', line 10 def evaluate line, lnum, file, formatter matched_ops = @ops.select do |op| op.evaluate line, lnum, file, formatter end if is_match? matched_ops lastmatch = matched_ops[-1] @last_start = lastmatch.start_position @last_end = lastmatch.end_position @match_line_number = lnum add_match lnum true else false end end |
#explain(level = 0) ⇒ Object
36 37 38 39 40 |
# File 'lib/glark/match/or.rb', line 36 def explain level = 0 str = " " * level + criteria + ":\n" str += @ops.collect { |op| op.explain(level + 4) }.join(" " * level + operator + "\n") str end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/glark/match/or.rb', line 28 def inspect "(" + @ops.collect { |op| op.to_s }.join(" " + operator + " ") + ")" end |