class See5::GritbotOutputParser

Read Gritbot output and return an array of hashes representing the anomalies

Attributes

anomalies[R]

Public Class Methods

new(fname) click to toggle source
# File lib/see5/gritbot_output_parser.rb, line 12
def initialize(fname)
  @file = File.open(fname)
  @anomalies = []

  parse_file
end
parse_file(fname) click to toggle source
# File lib/see5/gritbot_output_parser.rb, line 8
def self.parse_file(fname)
  new(fname).anomalies
end

Public Instance Methods

parse_file() click to toggle source
# File lib/see5/gritbot_output_parser.rb, line 19
def parse_file
  discard_header

  while (line = lines.next)
    if line.start_with?(/\s*while checking/)
      # TODO record excluded cases
    elsif line.start_with?(/(:?test |data )?case /)
      @anomalies << parse_anomaly(line)
    elsif line.start_with?("Time:")
      break
    end
  end
end

Private Instance Methods

discard_header() click to toggle source

Discard the file header and advance to the anomalies section

# File lib/see5/gritbot_output_parser.rb, line 41
def discard_header
  while (line = lines.next)
    break if line.start_with?(/\d+ possible anomal/)
  end
  # discard the final blank line
  lines.next
end
lines() click to toggle source
# File lib/see5/gritbot_output_parser.rb, line 35
def lines
  # TODO: lazy unnecessary given that rules are small?
  @file.each_line.lazy
end
parse_anomaly(line) click to toggle source
# File lib/see5/gritbot_output_parser.rb, line 49
def parse_anomaly(line)
  info = parse_anomaly_info_line(line)
  value = parse_anomaly_value_line(lines.next)

  conditions = []
  while (line = lines.next.strip)
    break if line == ""

    conditions << parse_condition_line(line)
  end

  # TODO new class for these
  {
    **info,
    **value,
    conditions: conditions
  }
end
parse_anomaly_info_line(line) click to toggle source
# File lib/see5/gritbot_output_parser.rb, line 68
def parse_anomaly_info_line(line)
  matches = line.match(/.*case (.*): (.*)\[([\.\d]+)\]/)

  {
    case_index: matches[1],
    case_label: matches[2].strip.delete_prefix("(label ").delete_suffix(")"),
    signifigance: matches[3].to_f
  }
end
parse_anomaly_value_line(line) click to toggle source
# File lib/see5/gritbot_output_parser.rb, line 78
def parse_anomaly_value_line(line)
  matches = line.match(/(.*) = (\S*)\s*\((.*)\)/)

  {
    attribute: matches[1].strip,
    value: matches[2],
    reason: matches[3]
  }
end
parse_condition_line(line) click to toggle source
# File lib/see5/gritbot_output_parser.rb, line 88
def parse_condition_line(line)
  line.strip
end