Sha256: 3e540af7d436a02a4478d8ba3486daaf60a587a74fdff0e5d6e57a224603e0ac

Contents?: true

Size: 745 Bytes

Versions: 7

Compression:

Stored size: 745 Bytes

Contents

# frozen_string_literal: true

module LogAnalyser
  class Parser
    class FileNotFoundError < StandardError
      def initialize(path)
        super("File not found for path: [#{path}]")
      end
    end

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

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

    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

    private

    attr_reader :entries

    def parse(data)
      data.each do |entry|
        key, value = *entry.split(/\s+/)
        entries[key] << value
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
log-analyser-0.1.3.pre.littleimprovements.20201109113028 lib/parser.rb
log-analyser-0.1.3.pre.littleimprovements.20201109103434 lib/parser.rb
log-analyser-0.1.3.pre.littleimprovements.20201109101712 lib/parser.rb
log-analyser-0.1.3 lib/parser.rb
log-analyser-0.1.3.pre.documentation.20201108213613 lib/parser.rb
log-analyser-0.1.3.pre.documentation.20201108213409 lib/parser.rb
log-analyser-0.1.3.pre.documentation.20201108212148 lib/parser.rb