Class: LogAnalyser::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/parser.rb

Defined Under Namespace

Classes: FileNotFoundError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



15
16
17
# File 'lib/parser.rb', line 15

def initialize
  @entries = Hash.new { |h, k| h[k] = [] }
end

Class Method Details

.call(file_path) ⇒ Object



11
12
13
# File 'lib/parser.rb', line 11

def self.call(file_path)
  new.call(file_path)
end

Instance Method Details

#call(file_path) ⇒ Object

Raises:



19
20
21
22
23
24
25
26
27
# File 'lib/parser.rb', line 19

def call(file_path)
  raise FileNotFoundError, file_path unless File.exist?(file_path)

  data = File.open(file_path).map(&:strip)
  data.reject!(&:empty?)
  parse(data)

  entries
end