Class: RSCM::AbstractLogParser
- Inherits:
-
Object
- Object
- RSCM::AbstractLogParser
- Defined in:
- lib/rscm/abstract_log_parser.rb
Overview
NOTE: It is recommended to use the Parser class in parser.rb as a basis for new SCM parsers
Some utilities for log-parsers TODO: make this a module and remove the attr_reader
Direct Known Subclasses
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #convert_all_slashes_to_forward_slashes(file) ⇒ Object
- #error(msg) ⇒ Object
- #had_error? ⇒ Boolean
-
#initialize(io) ⇒ AbstractLogParser
constructor
A new instance of AbstractLogParser.
- #read_until_matching_line(regexp) ⇒ Object
Constructor Details
#initialize(io) ⇒ AbstractLogParser
Returns a new instance of AbstractLogParser.
12 13 14 15 16 |
# File 'lib/rscm/abstract_log_parser.rb', line 12 def initialize(io) @io = io @current_line_number = 0 @had_error = false end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
10 11 12 |
# File 'lib/rscm/abstract_log_parser.rb', line 10 def io @io end |
Instance Method Details
#convert_all_slashes_to_forward_slashes(file) ⇒ Object
34 35 36 |
# File 'lib/rscm/abstract_log_parser.rb', line 34 def convert_all_slashes_to_forward_slashes(file) file.gsub(/\\/, "/") end |
#error(msg) ⇒ Object
38 39 40 41 42 |
# File 'lib/rscm/abstract_log_parser.rb', line 38 def error(msg) @had_error=true $stderr.puts(msg + "\ncurrent line: #{@current_line}\nstack trace:\n") $stderr.puts(caller.backtrace.join('\n\t')) end |
#had_error? ⇒ Boolean
44 45 46 |
# File 'lib/rscm/abstract_log_parser.rb', line 44 def had_error? @had_error end |
#read_until_matching_line(regexp) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rscm/abstract_log_parser.rb', line 18 def read_until_matching_line(regexp) return nil if io.eof? result = "" io.each_line do |line| @current_line_number += 1 line.gsub!(/\r\n$/, "\n") break if line=~regexp result<<line end if result.strip == "" read_until_matching_line(regexp) else result end end |