Class: LogMaster::LogFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, reporting_configuration = {}) ⇒ LogFile

Returns a new instance of LogFile.



5
6
7
8
# File 'lib/log_master/log_file.rb', line 5

def initialize(file_path, reporting_configuration={})
  @file_path = file_path
  @reporting_configuration = reporting_configuration
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



3
4
5
# File 'lib/log_master/log_file.rb', line 3

def file_path
  @file_path
end

Instance Method Details

#analyzeObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/log_master/log_file.rb', line 10

def analyze
  reports = @reporting_configuration.keys.inject({}) {|h,l| h.merge(l => 0)}
  
  if log_file_exists?
    @reporting_configuration.each do |report_name, report_regexp|
      reports[report_name] = body.scan(report_regexp).size
    end
  end
  
  reports
end

#bodyObject



30
31
32
# File 'lib/log_master/log_file.rb', line 30

def body
  log_file_exists? ? File.read(file_path) : "File Missing"
end

#file_nameObject



22
23
24
# File 'lib/log_master/log_file.rb', line 22

def file_name
  File.basename(file_path)
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/log_master/log_file.rb', line 26

def valid?
  log_file_exists?
end