Class: LogMaster::LogFile
- Inherits:
-
Object
- Object
- LogMaster::LogFile
- Defined in:
- lib/log_master/log_file.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
Instance Method Summary collapse
- #analyze ⇒ Object
- #body ⇒ Object
- #file_name ⇒ Object
-
#initialize(file_path, reporting_configuration = {}) ⇒ LogFile
constructor
A new instance of LogFile.
- #valid? ⇒ Boolean
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_path ⇒ Object
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
#analyze ⇒ Object
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 |
#body ⇒ Object
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_name ⇒ Object
22 23 24 |
# File 'lib/log_master/log_file.rb', line 22 def file_name File.basename(file_path) end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/log_master/log_file.rb', line 26 def valid? log_file_exists? end |