class LogAnalyser::Parser
Attributes
entries[R]
Public Class Methods
call(file_path)
click to toggle source
# File lib/parser.rb 11 def self.call(file_path) 12 new.call(file_path) 13 end
new()
click to toggle source
# File lib/parser.rb 15 def initialize 16 @entries = Hash.new { |h, k| h[k] = [] } 17 end
Public Instance Methods
call(file_path)
click to toggle source
# File lib/parser.rb 19 def call(file_path) 20 raise FileNotFoundError, file_path unless File.exist?(file_path) 21 22 data = File.open(file_path).map(&:strip) 23 data.reject!(&:empty?) 24 parse(data) 25 26 entries 27 end
Private Instance Methods
parse(data)
click to toggle source
# File lib/parser.rb 33 def parse(data) 34 data.each do |entry| 35 key, value = *entry.split(/\s+/) 36 entries[key] << value 37 end 38 end