Class: Snoopit::Detected

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comment, pre_before, after, match, file, line_no) ⇒ Detected

Returns a new instance of Detected.



6
7
8
9
10
11
12
13
14
15
# File 'lib/snoopit/detected.rb', line 6

def initialize(comment, pre_before, after, match, file, line_no)
  setup_before pre_before
  @comment     = comment
  @after_count = 0
  @after       = Register.new(after)
  @match       = match
  @file        = file
  @line_no     = line_no
  @finished    = false
end

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after.



4
5
6
# File 'lib/snoopit/detected.rb', line 4

def after
  @after
end

#after_countObject (readonly)

Returns the value of attribute after_count.



4
5
6
# File 'lib/snoopit/detected.rb', line 4

def after_count
  @after_count
end

#beforeObject (readonly)

Returns the value of attribute before.



4
5
6
# File 'lib/snoopit/detected.rb', line 4

def before
  @before
end

#commentObject (readonly)

Returns the value of attribute comment.



4
5
6
# File 'lib/snoopit/detected.rb', line 4

def comment
  @comment
end

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/snoopit/detected.rb', line 4

def file
  @file
end

#finishedObject (readonly)

Returns the value of attribute finished.



4
5
6
# File 'lib/snoopit/detected.rb', line 4

def finished
  @finished
end

#line_noObject (readonly)

Returns the value of attribute line_no.



4
5
6
# File 'lib/snoopit/detected.rb', line 4

def line_no
  @line_no
end

#matchObject (readonly)

Returns the value of attribute match.



4
5
6
# File 'lib/snoopit/detected.rb', line 4

def match
  @match
end

#regexpObject (readonly)

Returns the value of attribute regexp.



4
5
6
# File 'lib/snoopit/detected.rb', line 4

def regexp
  @regexp
end

Instance Method Details

#as_json(options = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/snoopit/detected.rb', line 35

def as_json(options=nil)
  {
      after: @after,
      match: @match,
      before: @before,
      file: @file,
      line_no: @line_no
  }
end

#finished?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/snoopit/detected.rb', line 31

def finished?
  @finished
end

#setup_before(pre_before) ⇒ Object



17
18
19
# File 'lib/snoopit/detected.rb', line 17

def setup_before(pre_before)
  @before = Register.new pre_before.size, pre_before.register
end

#to_json(*a) ⇒ Object



45
46
47
# File 'lib/snoopit/detected.rb', line 45

def to_json(*a)
  as_json.to_json(*a)
end

#track(line) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/snoopit/detected.rb', line 21

def track(line)
  return if line == @match
  if @after_count < @after.size
    @after.push_front line
    @after_count += 1
  else
    @finished = true
  end
end