Sha256: 3ff5976d204fe1f86edb89c21fa075543a1fc91df645d22bb29a3eb90895b0b4

Contents?: true

Size: 1.08 KB

Versions: 21

Compression:

Stored size: 1.08 KB

Contents

module RSCM
  
  # 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
  class AbstractLogParser
  
    attr_reader :io
  
    def initialize(io)
      @io = io
      @current_line_number = 0
      @had_error = false
    end
  
    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
    
    def convert_all_slashes_to_forward_slashes(file)
      file.gsub(/\\/, "/")
    end
    
    def error(msg)
      @had_error=true
      $stderr.puts(msg + "\ncurrent line: #{@current_line}\nstack trace:\n")
      $stderr.puts(caller.backtrace.join('\n\t'))
    end
    
    def had_error?
      @had_error
    end
  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rscm-0.1.0.1337 lib/rscm/abstract_log_parser.rb
rscm-0.1.0.1338 lib/rscm/abstract_log_parser.rb
rscm-0.1.0.999 lib/rscm/abstract_log_parser.rb
rscm-0.3.10 lib/rscm/abstract_log_parser.rb
rscm-0.3.3 lib/rscm/abstract_log_parser.rb
rscm-0.3.14 lib/rscm/abstract_log_parser.rb
rscm-0.2.0 lib/rscm/abstract_log_parser.rb
rscm-0.3.0 lib/rscm/abstract_log_parser.rb
rscm-0.3.5 lib/rscm/abstract_log_parser.rb
rscm-0.3.13 lib/rscm/abstract_log_parser.rb
rscm-0.1.0 lib/rscm/abstract_log_parser.rb
rscm-0.3.11 lib/rscm/abstract_log_parser.rb
rscm-0.3.1 lib/rscm/abstract_log_parser.rb
rscm-0.3.12 lib/rscm/abstract_log_parser.rb
rscm-0.3.2 lib/rscm/abstract_log_parser.rb
rscm-0.3.4 lib/rscm/abstract_log_parser.rb
rscm-0.2.1.1404 lib/rscm/abstract_log_parser.rb
rscm-0.3.6 lib/rscm/abstract_log_parser.rb
rscm-0.3.9 lib/rscm/abstract_log_parser.rb
rscm-0.3.7 lib/rscm/abstract_log_parser.rb