class Alicorn::LogParser
Constants
- SAMPLE_REGEX
Attributes
filename[RW]
samples[RW]
Public Class Methods
new(file = "alicorn.log")
click to toggle source
# File lib/alicorn/log_parser.rb, line 7 def initialize(file = "alicorn.log") self.filename = file self.samples = [] end
Public Instance Methods
parse()
click to toggle source
# File lib/alicorn/log_parser.rb, line 12 def parse f = File.open(filename) f.each do |line| sample_line(line) end samples end
Private Instance Methods
sample_line(line)
click to toggle source
Not suitable for calling in isolation, since an actual data sample spans 5 lines in the log file. This method checks for lines indicating either the beginning or end of a sample, or for data lines in the middle.
# File lib/alicorn/log_parser.rb, line 25 def sample_line(line) if line.match(/Sampling/) @sample_hash = {} # reset for the new sample elsif match_result = line.match(SAMPLE_REGEX) data = match_result[:values].split(", ").map(&:to_i) @sample_hash[match_result[:sample_type].to_sym] = (DataSet.new << data).flatten elsif line.match(/target calculated at:/) samples << @sample_hash # store the old sample end end