Class: Expression

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/glark/match/expression.rb

Overview

An expression, which can be applied (processed) against a Glark::File.

Direct Known Subclasses

CompoundExpression, RegexpExpression

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExpression

Returns a new instance of Expression.



16
17
18
19
# File 'lib/glark/match/expression.rb', line 16

def initialize
  @match_line_number = nil
  @matches = Array.new
end

Instance Attribute Details

#matchesObject

Returns the value of attribute matches.



14
15
16
# File 'lib/glark/match/expression.rb', line 14

def matches
  @matches
end

Instance Method Details

#add_match(lnum) ⇒ Object



21
22
23
# File 'lib/glark/match/expression.rb', line 21

def add_match lnum
  @matches.push lnum
end

#end_positionObject



29
30
31
# File 'lib/glark/match/expression.rb', line 29

def end_position
  start_position
end

#process(file, formatter) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/glark/match/expression.rb', line 38

def process file, formatter
  reset_file file.fname

  rgstart = file.get_range_start
  rgend = file.get_range_end
  
  lastmatch = 0
  lnum = 0
  file.each_line do |line|
    if ((!rgstart || lnum >= rgstart) && 
        (!rgend   || lnum < rgend)   &&
        evaluate(line, lnum, file, formatter))

      break if formatter.process_match start_position, end_position, lastmatch, lnum
      lastmatch = lnum + 1
    end
    lnum += 1
  end

  formatter.process_end lnum
end

#reset_file(file) ⇒ Object



33
34
35
36
# File 'lib/glark/match/expression.rb', line 33

def reset_file file
  @match_line_number = nil
  @matches = Array.new
end

#start_positionObject



25
26
27
# File 'lib/glark/match/expression.rb', line 25

def start_position
  @match_line_number
end

#to_sObject



60
61
62
# File 'lib/glark/match/expression.rb', line 60

def to_s
  inspect
end