Module: RSlog::Main

Extended by:
ArgsHandler, Validator
Defined in:
lib/rslog.rb

Overview

Module to hold main process

Constant Summary

Constants included from Validator

Validator::MESSAGES, Validator::TEMPLATES

Class Method Summary collapse

Methods included from ArgsHandler

file_names_from_args

Methods included from Validator

validate

Class Method Details

._config_setsObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/rslog.rb', line 42

def self._config_sets
  [{ title:       %(List of webpages with most page views ordered from most pages views to less page views:),
     #          head_titles:     %w[Url Visits Average],
     head_titles: %w[Url Visits],
     calc:        proc { |visits| visits.size } },
   { title:       'List of webpages with most unique page views also ordered:',
     #          head_titles:     %w[Url Unique\ views Average],
     head_titles: %w[Url Unique\ views],
     calc:        proc { |visits| Set.new(visits).size } } ]
end

._process(lines) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/rslog.rb', line 33

def self._process(lines)
  decorator = RSlog::Decorator.new(:utf)
  _config_sets.each do |conf|
    data_processing = RSlog::DataProcessing.new(lines, conf)
    parsed_data = RSlog::Parser.new(data_processing).parse
    RSlog::Presenter.new(parsed_data, conf, decorator).present
  end
end

.runObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rslog.rb', line 21

def self.run
  file_names_from_args(ARGV).each do |file_name|
    puts "Statistics for file #{file_name}"

    lines = IO.readlines(file_name)

    validate(lines)

    _process(lines)
  end
end