rslog 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rslog.rb +14 -17
- data/lib/rslog/args_handler.rb +15 -9
- data/lib/rslog/parser.rb +5 -51
- data/lib/rslog/validator.rb +5 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52bf0a8fd868cb749fcd759adfb7782a5cba4b148f15f6f52b913147dd6fa95d
|
|
4
|
+
data.tar.gz: a15d5b6d9ad034f6ffd962e47757ed7f3878c25aee4bace3d5d27bbe79d033b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 916951619a9a3949fe6c4b5d3d2f9f684d3eaf7107d5cba15162d5402009a24187a61baea8ce0dab153c2315a06045956e49bf25eb2b9aec6b1b85871f198788
|
|
7
|
+
data.tar.gz: 071e2abb7278a4a84aaa2cec1154a5e63c83971746d5cdacd7b32127d5c36225e43f772b22ccff342a73f24d4d4d185743e971d2c9903f5ae2d7f86031594433
|
data/lib/rslog.rb
CHANGED
|
@@ -3,44 +3,41 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative 'rslog/args_handler'
|
|
5
5
|
require_relative 'rslog/validator'
|
|
6
|
+
require_relative 'rslog/data_processing'
|
|
6
7
|
require_relative 'rslog/parser'
|
|
7
8
|
require_relative 'rslog/presenter'
|
|
8
9
|
require 'set'
|
|
9
10
|
|
|
10
11
|
module RSlog
|
|
11
|
-
VERSION = '0.0.
|
|
12
|
+
VERSION = '0.0.17'
|
|
12
13
|
|
|
13
14
|
# Module to hold main process
|
|
14
15
|
#
|
|
15
16
|
module Main
|
|
17
|
+
extend RSlog::ArgsHandler
|
|
18
|
+
extend RSlog::Validator
|
|
19
|
+
|
|
16
20
|
def self.run
|
|
17
|
-
|
|
21
|
+
file_names_from_args(ARGV).each do |file_name|
|
|
18
22
|
puts "Statistics for file #{file_name}"
|
|
19
23
|
|
|
20
24
|
lines = IO.readlines(file_name)
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
validate(lines)
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
_process(lines)
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
|
|
28
|
-
def self.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
RSlog::
|
|
32
|
+
def self._process(lines)
|
|
33
|
+
_config_sets.each do |conf|
|
|
34
|
+
data_processing = RSlog::DataProcessing.new(lines, conf)
|
|
35
|
+
parsed_data = RSlog::Parser.new(data_processing).parse
|
|
36
|
+
RSlog::Presenter.new(parsed_data, conf).present
|
|
32
37
|
end
|
|
33
38
|
end
|
|
34
39
|
|
|
35
|
-
def self.
|
|
36
|
-
file_names = RSlog::ArgsHandler.new(ARGV).handle
|
|
37
|
-
return file_names if file_names.all? { |file_name| File.file?(file_name) }
|
|
38
|
-
|
|
39
|
-
puts 'There is no file names given. Check input.'
|
|
40
|
-
[]
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def self.config_sets
|
|
40
|
+
def self._config_sets
|
|
44
41
|
[{ title: %(List of webpages with most page views ordered from most pages views to less page views:),
|
|
45
42
|
# head_titles: %w[Url Visits Average],
|
|
46
43
|
head_titles: %w[Url Visits],
|
data/lib/rslog/args_handler.rb
CHANGED
|
@@ -5,22 +5,28 @@ module RSlog
|
|
|
5
5
|
#
|
|
6
6
|
# returns Array of file names
|
|
7
7
|
#
|
|
8
|
-
|
|
9
|
-
attr_reader :args, :options
|
|
8
|
+
module ArgsHandler
|
|
9
|
+
# attr_reader :args, :options
|
|
10
|
+
#
|
|
11
|
+
# def initialize(args)
|
|
12
|
+
# @args = args
|
|
13
|
+
# @options = @args.select { |el| el =~ /^-/ }
|
|
14
|
+
# end
|
|
10
15
|
|
|
11
|
-
def
|
|
16
|
+
def file_names_from_args(args)
|
|
12
17
|
@args = args
|
|
13
18
|
@options = @args.select { |el| el =~ /^-/ }
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def handle
|
|
17
|
-
if options.any? || args.empty?
|
|
19
|
+
if @options.any? || @args.empty?
|
|
18
20
|
_handle_options
|
|
19
21
|
return []
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
# file_names array
|
|
23
|
-
args - options
|
|
25
|
+
file_names = @args - @options
|
|
26
|
+
return file_names if file_names.all? { |file_name| File.file?(file_name) }
|
|
27
|
+
|
|
28
|
+
puts 'There is no file names given. Check input.'
|
|
29
|
+
[]
|
|
24
30
|
end
|
|
25
31
|
|
|
26
32
|
private
|
|
@@ -30,7 +36,7 @@ module RSlog
|
|
|
30
36
|
end
|
|
31
37
|
|
|
32
38
|
def _show_help
|
|
33
|
-
if options.delete('-h') || args.empty?
|
|
39
|
+
if @options.delete('-h') || @args.empty?
|
|
34
40
|
puts _help_message
|
|
35
41
|
return true
|
|
36
42
|
end
|
data/lib/rslog/parser.rb
CHANGED
|
@@ -1,54 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# Class to hold data_processing methods
|
|
5
|
-
#
|
|
6
|
-
class DataProcessing
|
|
7
|
-
attr_reader :result
|
|
3
|
+
require 'forwardable'
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
@calc = conf.fetch(:calc) { proc }
|
|
11
|
-
@separator = conf.fetch(:separator, ' ')
|
|
12
|
-
@result = Array(source)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# extract
|
|
16
|
-
def extract
|
|
17
|
-
@result = @result.map { |item| item.split(@separator) }
|
|
18
|
-
self
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# group
|
|
22
|
-
def group
|
|
23
|
-
@result = @result.group_by { |url, _visits| url }.to_a
|
|
24
|
-
self
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# calculate
|
|
28
|
-
def calculate
|
|
29
|
-
# calculate visits
|
|
30
|
-
@result = @result.map { |url, visits| [url, @calc.call(visits)] }
|
|
31
|
-
# calculate average
|
|
32
|
-
# @result = @result.map { |url, visits_qty| [url, visits_qty, (visits_qty.to_f / _total)] }
|
|
33
|
-
self
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# sort
|
|
37
|
-
def order
|
|
38
|
-
@result = @result.sort_by { |_url, visits_by_page| visits_by_page }
|
|
39
|
-
@result.reverse!
|
|
40
|
-
self
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
# calculate total
|
|
46
|
-
def _total
|
|
47
|
-
@result.sum { |_url, visits_qty| visits_qty }
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
require 'forwardable'
|
|
5
|
+
module RSlog
|
|
52
6
|
# Class to parse data
|
|
53
7
|
#
|
|
54
8
|
class Parser
|
|
@@ -57,11 +11,11 @@ module RSlog
|
|
|
57
11
|
extend Forwardable
|
|
58
12
|
def_delegators :@data_processing, :extract, :group, :calculate, :order
|
|
59
13
|
|
|
60
|
-
def initialize(
|
|
61
|
-
@data_processing =
|
|
14
|
+
def initialize(data_processing)
|
|
15
|
+
@data_processing = data_processing
|
|
62
16
|
end
|
|
63
17
|
|
|
64
|
-
def
|
|
18
|
+
def parse
|
|
65
19
|
data_processing.extract.group.calculate.order.result
|
|
66
20
|
end
|
|
67
21
|
end
|
data/lib/rslog/validator.rb
CHANGED
|
@@ -17,13 +17,15 @@ module RSlog
|
|
|
17
17
|
invalid: proc { |validator_name| "Some #{validator_name.upcase}s are NOT valid" }
|
|
18
18
|
}.freeze
|
|
19
19
|
|
|
20
|
-
def
|
|
20
|
+
def validate(source)
|
|
21
21
|
puts
|
|
22
|
-
puts MESSAGES[
|
|
22
|
+
puts MESSAGES[_valid?(source)].call(:ip)
|
|
23
23
|
puts
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def _valid?(source)
|
|
27
29
|
return :valid if source.all? TEMPLATES[:ip]
|
|
28
30
|
|
|
29
31
|
:invalid
|