rslog 0.0.4 → 0.0.9
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 +2 -1
- data/lib/rslog/container.rb +3 -3
- data/lib/rslog/data_parser.rb +3 -8
- data/lib/rslog/extractor.rb +5 -9
- data/lib/rslog/input_parser.rb +5 -9
- data/lib/rslog/opts.rb +29 -0
- data/lib/rslog/presenter.rb +6 -11
- data/lib/rslog/tools/array.rb +3 -3
- data/lib/rslog/validator.rb +2 -6
- data/lib/rslog/worker.rb +13 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6ce0368ae8830da116ff45bb102f0156e0ff0c320f57ddb0ba133efa019b7460
|
|
4
|
+
data.tar.gz: b12a734d292403f0dfabe560e22e170ec1f4e72d9a07227f80291d5aeb72c51b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 277bec231152641cbd79ad42f7737f7bccf69e2abb5d804d0a976c42d6a4f353fac5761555e7a662bb7767eb6c7ad7499e2716ea9305e343b2c7b542178a3540
|
|
7
|
+
data.tar.gz: 8b245fc399ac058b0cad266fd1684cbfa76136d8b2c02e6bc1c088441482758b54e8a5a25d00f2de50ce9889ad42a3ba02ba92ba85594ab1aaa32680e1e59896
|
data/lib/rslog.rb
CHANGED
|
@@ -7,12 +7,13 @@ require_relative 'rslog/extractor'
|
|
|
7
7
|
require_relative 'rslog/validator'
|
|
8
8
|
require_relative 'rslog/data_parser'
|
|
9
9
|
require_relative 'rslog/presenter'
|
|
10
|
+
require_relative 'rslog/opts'
|
|
10
11
|
|
|
11
12
|
# For development
|
|
12
13
|
# require 'pry'
|
|
13
14
|
|
|
14
15
|
class RSlog
|
|
15
|
-
VERSION = '0.0.
|
|
16
|
+
VERSION = '0.0.9'
|
|
16
17
|
|
|
17
18
|
def self.run
|
|
18
19
|
Container.new.process_all
|
data/lib/rslog/container.rb
CHANGED
data/lib/rslog/data_parser.rb
CHANGED
|
@@ -2,24 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'tools/array'
|
|
4
4
|
require_relative 'tools/hash'
|
|
5
|
+
require_relative 'worker'
|
|
5
6
|
require_relative 'validator'
|
|
6
7
|
|
|
7
|
-
require 'pry'
|
|
8
|
-
|
|
9
8
|
# Class to parse data from given array
|
|
10
9
|
#
|
|
11
|
-
class DataParser
|
|
10
|
+
class DataParser < Worker
|
|
12
11
|
# type = :count (default) -> just count in groups
|
|
13
12
|
# type = :uniq -> uniq entries in groups
|
|
14
|
-
def initialize(container)
|
|
15
|
-
@container = container
|
|
16
|
-
end
|
|
17
|
-
|
|
18
13
|
def execute(type)
|
|
19
14
|
@container.result =
|
|
20
15
|
@container.data
|
|
21
16
|
.group_by_index(0)
|
|
22
|
-
.send("count_by_groups_#{type
|
|
17
|
+
.send("count_by_groups_#{type}")
|
|
23
18
|
.to_a
|
|
24
19
|
.sort_by { |item| item[1] }
|
|
25
20
|
.reverse
|
data/lib/rslog/extractor.rb
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative '
|
|
3
|
+
require_relative 'worker'
|
|
4
4
|
|
|
5
5
|
# Class for extracting data from file
|
|
6
6
|
#
|
|
7
|
-
class Extractor
|
|
8
|
-
def initialize(container)
|
|
9
|
-
@container = container
|
|
10
|
-
@file_name = container.file_name
|
|
11
|
-
end
|
|
12
|
-
|
|
7
|
+
class Extractor < Worker
|
|
13
8
|
def execute
|
|
9
|
+
@file_name = @container.file_name
|
|
14
10
|
check
|
|
15
11
|
self
|
|
16
12
|
end
|
|
@@ -24,7 +20,7 @@ class Extractor
|
|
|
24
20
|
@container.data = File.open(@file_name, 'r').to_a
|
|
25
21
|
@container.add_message 'Data in place'
|
|
26
22
|
end
|
|
27
|
-
rescue StandardError =>
|
|
28
|
-
@container.add_error
|
|
23
|
+
rescue StandardError => e
|
|
24
|
+
@container.add_error e
|
|
29
25
|
end
|
|
30
26
|
end
|
data/lib/rslog/input_parser.rb
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'optparse'
|
|
4
|
+
require_relative 'worker'
|
|
4
5
|
require_relative 'opts'
|
|
5
6
|
|
|
6
7
|
# Class to parse input filenames and args
|
|
7
8
|
#
|
|
8
|
-
class InputParser
|
|
9
|
+
class InputParser < Worker
|
|
9
10
|
include Opts
|
|
10
11
|
|
|
11
|
-
def initialize(container)
|
|
12
|
-
@container = container
|
|
13
|
-
end
|
|
14
|
-
|
|
15
12
|
def execute
|
|
16
|
-
@opts = Opts.create_opts
|
|
17
13
|
handle_opts
|
|
18
14
|
handle_args
|
|
19
15
|
self
|
|
@@ -24,9 +20,9 @@ class InputParser
|
|
|
24
20
|
attr_accessor :opts
|
|
25
21
|
|
|
26
22
|
def handle_opts
|
|
27
|
-
|
|
28
|
-
rescue OptionParser::InvalidOption =>
|
|
29
|
-
@container.add_error
|
|
23
|
+
Opts.create_opts.parse!(into: @container.options)
|
|
24
|
+
rescue OptionParser::InvalidOption => e
|
|
25
|
+
@container.add_error e
|
|
30
26
|
end
|
|
31
27
|
|
|
32
28
|
def handle_args
|
data/lib/rslog/opts.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Service module to give opts
|
|
4
|
+
#
|
|
5
|
+
module Opts
|
|
6
|
+
VERSION = {
|
|
7
|
+
descr: ['-v', '--version', 'Show version and exit'],
|
|
8
|
+
action: proc do
|
|
9
|
+
puts "#{File.basename($PROGRAM_NAME)}: #{RSlog::VERSION}"
|
|
10
|
+
exit
|
|
11
|
+
end
|
|
12
|
+
}.freeze
|
|
13
|
+
|
|
14
|
+
HELP = {
|
|
15
|
+
descr: ['-h', '--help', 'Prints this message and exit'],
|
|
16
|
+
action: proc do |opts|
|
|
17
|
+
puts opts
|
|
18
|
+
exit
|
|
19
|
+
end
|
|
20
|
+
}.freeze
|
|
21
|
+
|
|
22
|
+
def self.create_opts
|
|
23
|
+
OptionParser.new do |opts|
|
|
24
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} FILENAME"
|
|
25
|
+
opts.on(*Opts::VERSION[:descr]) { Opts::VERSION[:action].call }
|
|
26
|
+
opts.on(*Opts::HELP[:descr]) { Opts::HELP[:action].call(opts) }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/rslog/presenter.rb
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'worker'
|
|
3
4
|
require_relative 'tools/hash'
|
|
4
5
|
require_relative 'tools/array'
|
|
5
6
|
|
|
6
7
|
# Class to present result in needed format
|
|
7
8
|
#
|
|
8
|
-
class Presenter
|
|
9
|
+
class Presenter < Worker
|
|
9
10
|
DECORATORS = {
|
|
10
11
|
all: {
|
|
11
12
|
title:
|
|
@@ -18,32 +19,26 @@ class Presenter
|
|
|
18
19
|
}
|
|
19
20
|
}.freeze
|
|
20
21
|
|
|
21
|
-
def initialize(container)
|
|
22
|
-
@container = container
|
|
23
|
-
end
|
|
24
|
-
|
|
25
22
|
def execute(type, formatter)
|
|
26
23
|
@type = type
|
|
27
|
-
@container.
|
|
24
|
+
@container.add_message send("format_as_#{formatter}")
|
|
28
25
|
self
|
|
29
26
|
end
|
|
30
27
|
|
|
31
28
|
private
|
|
32
29
|
|
|
33
|
-
attr_reader :title, :suffix
|
|
34
|
-
|
|
35
30
|
def title
|
|
36
31
|
decorator[:title]
|
|
37
32
|
end
|
|
38
|
-
|
|
33
|
+
|
|
39
34
|
def suffix
|
|
40
35
|
decorator[:suffix]
|
|
41
36
|
end
|
|
42
|
-
|
|
37
|
+
|
|
43
38
|
def decorator
|
|
44
39
|
DECORATORS[@type]
|
|
45
40
|
end
|
|
46
|
-
|
|
41
|
+
|
|
47
42
|
def format_as_text
|
|
48
43
|
[
|
|
49
44
|
title,
|
data/lib/rslog/tools/array.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Monkey patch for Array class
|
|
4
|
-
#
|
|
3
|
+
# Monkey patch for Array class
|
|
4
|
+
#
|
|
5
5
|
class Array
|
|
6
6
|
def group_by_index(index = 0)
|
|
7
7
|
group_by { |str| str.split(' ')[index] }
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def to_multiline_string(suffix = '')
|
|
11
|
-
|
|
11
|
+
map { |item| "#{item} #{suffix}" }.join("\n")
|
|
12
12
|
end
|
|
13
13
|
end
|
data/lib/rslog/validator.rb
CHANGED
|
@@ -4,7 +4,7 @@ require_relative 'tools/array'
|
|
|
4
4
|
|
|
5
5
|
# Class to validate if we have valid data in lines, for example well formatted IPs
|
|
6
6
|
#
|
|
7
|
-
class Validator
|
|
7
|
+
class Validator < Worker
|
|
8
8
|
TEMPLATES = {
|
|
9
9
|
# IP address regex, source https://regexr.com/38odc
|
|
10
10
|
ip: /\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b/
|
|
@@ -15,12 +15,8 @@ class Validator
|
|
|
15
15
|
invalid: proc { |validator| "Some #{validator.upcase}s are NOT valid" }
|
|
16
16
|
}.freeze
|
|
17
17
|
|
|
18
|
-
def initialize(container)
|
|
19
|
-
@container = container
|
|
20
|
-
end
|
|
21
|
-
|
|
22
18
|
def execute
|
|
23
|
-
@container.
|
|
19
|
+
@container.add_message MESSAGES[validate].call(@container.validator)
|
|
24
20
|
self
|
|
25
21
|
end
|
|
26
22
|
|
data/lib/rslog/worker.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Class to hold worker functionality
|
|
4
|
+
#
|
|
5
|
+
class Worker
|
|
6
|
+
def initialize(container)
|
|
7
|
+
@container = container
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def execute
|
|
11
|
+
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
|
|
12
|
+
end
|
|
13
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rslog
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrey Eremeev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-03-
|
|
11
|
+
date: 2021-03-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Ruby script to get overall Statistic for weblog logs!
|
|
14
14
|
email: a.eremeev@outlook.com
|
|
@@ -23,10 +23,12 @@ files:
|
|
|
23
23
|
- lib/rslog/data_parser.rb
|
|
24
24
|
- lib/rslog/extractor.rb
|
|
25
25
|
- lib/rslog/input_parser.rb
|
|
26
|
+
- lib/rslog/opts.rb
|
|
26
27
|
- lib/rslog/presenter.rb
|
|
27
28
|
- lib/rslog/tools/array.rb
|
|
28
29
|
- lib/rslog/tools/hash.rb
|
|
29
30
|
- lib/rslog/validator.rb
|
|
31
|
+
- lib/rslog/worker.rb
|
|
30
32
|
homepage: https://rubygems.org/gems/rslog
|
|
31
33
|
licenses:
|
|
32
34
|
- MIT
|