class Parser::Reader
Constants
- VALID_EXTENSIONS
Attributes
file[RW]
Public Class Methods
new(file)
click to toggle source
# File lib/parser/reader.rb, line 9 def initialize(file) @file = file end
Public Instance Methods
call()
click to toggle source
# File lib/parser/reader.rb, line 13 def call validate_presence validate_extension aggregate end
Private Instance Methods
aggregate()
click to toggle source
# File lib/parser/reader.rb, line 35 def aggregate data = Hash.new { |h, key| h[key] = [] } file_lines.each do |line| path, ip = line.split data[path] << ip end data end
file_lines()
click to toggle source
# File lib/parser/reader.rb, line 31 def file_lines @file_lines ||= File.readlines file end
validate_extension()
click to toggle source
# File lib/parser/reader.rb, line 21 def validate_extension unless VALID_EXTENSIONS.include? File.extname(file) raise InvalidExtensionException, "File has to be .log or .txt" end end
validate_presence()
click to toggle source
# File lib/parser/reader.rb, line 27 def validate_presence raise FileNotFoundException, "File not found" unless file && File.exist?(file) end