Module: LogParser::RegExpPattern
- Includes:
- Pattern
- Included in:
- TexLogParser::BadHboxWarning, TexLogParser::FatalErrorOccurred, TexLogParser::FileLineError, TexLogParser::HighlightedMessages, TexLogParser::PrefixedMultiLinePattern, TexLogParser::RunawayParameterError, TexLogParser::StandardError
- Defined in:
- lib/log_parser/pattern.rb
Overview
Represents a certain pattern log message. The model we use is that
* a pattern tells you if a message starts in a given line, and
* reads lines from there on until it ends.
The result will be a Message.
This type of pattern is characterized mainly by two regular expressions:
* One for matching the first line of a message, and
* one for matching the last line (+- 1) of a message, which may depend on the first.
Instance Method Summary collapse
-
#begins_at?(line) ⇒ true, false
Checks if this message pattern matches the given line, that is whether the ‘start` regexp (see #initialize) matches it.
-
#initialize(start, ending = { pattern: ->(_) { /^\s*$/ }, until: :match, inclusive: false }) ⇒ Object
Creates a new instance.
-
#read(lines) ⇒ Array<(Message, Int)>
Reads a message from the given lines.
Instance Method Details
#begins_at?(line) ⇒ true, false
Checks if this message pattern matches the given line, that is whether the ‘start` regexp (see #initialize) matches it.
83 84 85 86 87 |
# File 'lib/log_parser/pattern.rb', line 83 def begins_at?(line) match = @start.match(line) @start_match = match unless match.nil? !match.nil? end |
#initialize(start, ending = { pattern: ->(_) { /^\s*$/ }, until: :match, inclusive: false }) ⇒ Object
Creates a new instance.
69 70 71 72 73 74 |
# File 'lib/log_parser/pattern.rb', line 69 def initialize(start, ending = { pattern: ->(_) { /^\s*$/ }, until: :match, inclusive: false }) @start = start @ending = ending end |
#read(lines) ⇒ Array<(Message, Int)>
Reads a message from the given lines.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/log_parser/pattern.rb', line 97 def read(lines) ending = lines.find_index(1) { |l| ends_at?(l) } raise "Did not find end of message (pattern '#{self.class}')." if ending.nil? ending -= 1 unless @ending[:inclusive] # Use ending+1 since ending is the index when we drop the first line! msg = LogParser::Message.new(message: lines[0, ending + 1].join("\n"), preformatted: true, level: nil, pattern: self.class) [msg, ending + 1] end |