Class: Snoopit::Detected
- Inherits:
-
Object
- Object
- Snoopit::Detected
- Defined in:
- lib/snoopit/detected.rb
Overview
When the sniffer detects a match it saves the contextual information in a Detected
instances
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#after_count ⇒ Object
readonly
Returns the value of attribute after_count.
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#finished ⇒ Object
readonly
Returns the value of attribute finished.
-
#line_no ⇒ Object
readonly
Returns the value of attribute line_no.
-
#match ⇒ Object
readonly
Returns the value of attribute match.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(comment, pre_before, after, match, file, line_no) ⇒ Detected
constructor
These are parameters from the match.
-
#setup_before(pre_before) ⇒ Object
Get the lines before the found match.
- #to_json(*a) ⇒ Object
-
#track(line) ⇒ Object
This collects the lines after a match is found.
Constructor Details
#initialize(comment, pre_before, after, match, file, line_no) ⇒ Detected
These are parameters from the match
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/snoopit/detected.rb', line 9 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
#after ⇒ Object (readonly)
Returns the value of attribute after.
6 7 8 |
# File 'lib/snoopit/detected.rb', line 6 def after @after end |
#after_count ⇒ Object (readonly)
Returns the value of attribute after_count.
6 7 8 |
# File 'lib/snoopit/detected.rb', line 6 def after_count @after_count end |
#before ⇒ Object (readonly)
Returns the value of attribute before.
6 7 8 |
# File 'lib/snoopit/detected.rb', line 6 def before @before end |
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
6 7 8 |
# File 'lib/snoopit/detected.rb', line 6 def comment @comment end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/snoopit/detected.rb', line 6 def file @file end |
#finished ⇒ Object (readonly)
Returns the value of attribute finished.
6 7 8 |
# File 'lib/snoopit/detected.rb', line 6 def finished @finished end |
#line_no ⇒ Object (readonly)
Returns the value of attribute line_no.
6 7 8 |
# File 'lib/snoopit/detected.rb', line 6 def line_no @line_no end |
#match ⇒ Object (readonly)
Returns the value of attribute match.
6 7 8 |
# File 'lib/snoopit/detected.rb', line 6 def match @match end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
6 7 8 |
# File 'lib/snoopit/detected.rb', line 6 def regexp @regexp end |
Instance Method Details
#as_json(options = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/snoopit/detected.rb', line 40 def as_json(=nil) { after: @after, match: @match, before: @before, file: @file, line_no: @line_no } end |
#finished? ⇒ Boolean
36 37 38 |
# File 'lib/snoopit/detected.rb', line 36 def finished? @finished end |
#setup_before(pre_before) ⇒ Object
Get the lines before the found match
21 22 23 |
# File 'lib/snoopit/detected.rb', line 21 def setup_before(pre_before) @before = Register.new pre_before.size, pre_before.register end |
#to_json(*a) ⇒ Object
50 51 52 |
# File 'lib/snoopit/detected.rb', line 50 def to_json(*a) as_json.to_json(*a) end |
#track(line) ⇒ Object
This collects the lines after a match is found
26 27 28 29 30 31 32 33 34 |
# File 'lib/snoopit/detected.rb', line 26 def track(line) return if line == @match if @after_count < @after.size @after.push_front line @after_count += 1 else @finished = true end end |