rslog 0.0.7 → 0.0.12
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 +1 -1
- data/lib/rslog/data_parser.rb +9 -16
- data/lib/rslog/extractor.rb +10 -13
- data/lib/rslog/input_parser.rb +5 -12
- data/lib/rslog/opts.rb +12 -4
- data/lib/rslog/presenter.rb +3 -7
- data/lib/rslog/validator.rb +3 -7
- data/lib/rslog/worker.rb +15 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 843ae99c81000576196f8fb4b3cb3be0a6a529b430f02d4f205b58e9def8f61c
|
|
4
|
+
data.tar.gz: 0e642e1dbb538480f037e7ed33b2129b99d31441ea5c44a51a45289f2fbe4e7e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ccce9aef8ab69e63c8162116aceb13500bd4e5cff99b318958313ab0897250e55b476cc467178ed70ff69b98d847f9593ee9f2f9d1e616403cf8e1ceb5e3ab35
|
|
7
|
+
data.tar.gz: 3065582ca9c1d32999faa78fc9675af66a83599222e39689b56875656cb69a715703a62e20f1910df622b776a8e6d18e730317398d2b7fd12f873739a53e9a5e
|
data/lib/rslog.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative 'rslog/container'
|
|
5
|
+
require_relative 'rslog/worker'
|
|
5
6
|
require_relative 'rslog/input_parser'
|
|
6
7
|
require_relative 'rslog/extractor'
|
|
7
8
|
require_relative 'rslog/validator'
|
|
@@ -13,7 +14,7 @@ require_relative 'rslog/opts'
|
|
|
13
14
|
# require 'pry'
|
|
14
15
|
|
|
15
16
|
class RSlog
|
|
16
|
-
VERSION = '0.0.
|
|
17
|
+
VERSION = '0.0.12'
|
|
17
18
|
|
|
18
19
|
def self.run
|
|
19
20
|
Container.new.process_all
|
data/lib/rslog/container.rb
CHANGED
data/lib/rslog/data_parser.rb
CHANGED
|
@@ -2,28 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'tools/array'
|
|
4
4
|
require_relative 'tools/hash'
|
|
5
|
-
require_relative 'validator'
|
|
6
|
-
|
|
7
|
-
require 'pry'
|
|
8
5
|
|
|
9
6
|
# Class to parse data from given array
|
|
10
7
|
#
|
|
11
|
-
class DataParser
|
|
8
|
+
class DataParser < Worker
|
|
12
9
|
# type = :count (default) -> just count in groups
|
|
13
10
|
# type = :uniq -> uniq entries in groups
|
|
14
|
-
def initialize(container)
|
|
15
|
-
@container = container
|
|
16
|
-
end
|
|
17
|
-
|
|
18
11
|
def execute(type)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
container.result =
|
|
13
|
+
container.data
|
|
14
|
+
.group_by_index(0)
|
|
15
|
+
.send("count_by_groups_#{type}")
|
|
16
|
+
.to_a
|
|
17
|
+
.sort_by { |item| item[1] }
|
|
18
|
+
.reverse
|
|
19
|
+
.map { |elem_arr| elem_arr.map(&:to_s).join(' ') }
|
|
27
20
|
self
|
|
28
21
|
end
|
|
29
22
|
end
|
data/lib/rslog/extractor.rb
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'container'
|
|
4
|
-
|
|
5
3
|
# Class for extracting data from file
|
|
6
4
|
#
|
|
7
|
-
class Extractor
|
|
8
|
-
def initialize(container)
|
|
9
|
-
@container = container
|
|
10
|
-
@file_name = container.file_name
|
|
11
|
-
end
|
|
12
|
-
|
|
5
|
+
class Extractor < Worker
|
|
13
6
|
def execute
|
|
14
7
|
check
|
|
15
8
|
self
|
|
@@ -17,14 +10,18 @@ class Extractor
|
|
|
17
10
|
|
|
18
11
|
private
|
|
19
12
|
|
|
13
|
+
def file_name
|
|
14
|
+
container.file_name
|
|
15
|
+
end
|
|
16
|
+
|
|
20
17
|
def check
|
|
21
|
-
if File.zero?(
|
|
22
|
-
|
|
18
|
+
if File.zero?(file_name)
|
|
19
|
+
container.add_message 'Empty file'
|
|
23
20
|
else
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
container.data = File.open(file_name, 'r').to_a
|
|
22
|
+
container.add_message 'Data in place'
|
|
26
23
|
end
|
|
27
24
|
rescue StandardError => e
|
|
28
|
-
|
|
25
|
+
container.add_error e
|
|
29
26
|
end
|
|
30
27
|
end
|
data/lib/rslog/input_parser.rb
CHANGED
|
@@ -5,15 +5,10 @@ require_relative 'opts'
|
|
|
5
5
|
|
|
6
6
|
# Class to parse input filenames and args
|
|
7
7
|
#
|
|
8
|
-
class InputParser
|
|
8
|
+
class InputParser < Worker
|
|
9
9
|
include Opts
|
|
10
10
|
|
|
11
|
-
def initialize(container)
|
|
12
|
-
@container = container
|
|
13
|
-
end
|
|
14
|
-
|
|
15
11
|
def execute
|
|
16
|
-
@opts = Opts.create_opts
|
|
17
12
|
handle_opts
|
|
18
13
|
handle_args
|
|
19
14
|
self
|
|
@@ -21,16 +16,14 @@ class InputParser
|
|
|
21
16
|
|
|
22
17
|
private
|
|
23
18
|
|
|
24
|
-
attr_accessor :opts
|
|
25
|
-
|
|
26
19
|
def handle_opts
|
|
27
|
-
|
|
20
|
+
Opts.create_opts.parse!(into: container.options)
|
|
28
21
|
rescue OptionParser::InvalidOption => e
|
|
29
|
-
|
|
22
|
+
container.add_error e
|
|
30
23
|
end
|
|
31
24
|
|
|
32
25
|
def handle_args
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
container.file_name = ARGV.select { |str| str =~ /.\.log|.\.txt/ }[0] || ''
|
|
27
|
+
container.add_error 'No file_name provided' if container.file_name.empty?
|
|
35
28
|
end
|
|
36
29
|
end
|
data/lib/rslog/opts.rb
CHANGED
|
@@ -7,7 +7,6 @@ module Opts
|
|
|
7
7
|
descr: ['-v', '--version', 'Show version and exit'],
|
|
8
8
|
action: proc do
|
|
9
9
|
puts "#{File.basename($PROGRAM_NAME)}: #{RSlog::VERSION}"
|
|
10
|
-
exit
|
|
11
10
|
end
|
|
12
11
|
}.freeze
|
|
13
12
|
|
|
@@ -15,15 +14,24 @@ module Opts
|
|
|
15
14
|
descr: ['-h', '--help', 'Prints this message and exit'],
|
|
16
15
|
action: proc do |opts|
|
|
17
16
|
puts opts
|
|
18
|
-
exit
|
|
19
17
|
end
|
|
20
18
|
}.freeze
|
|
21
19
|
|
|
22
20
|
def self.create_opts
|
|
23
21
|
OptionParser.new do |opts|
|
|
24
22
|
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} FILENAME"
|
|
25
|
-
opts
|
|
26
|
-
opts.on(*Opts::HELP[:descr])
|
|
23
|
+
help(opts)
|
|
24
|
+
opts.on(*Opts::HELP[:descr]) do
|
|
25
|
+
Opts::HELP[:action].call(opts)
|
|
26
|
+
exit
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.help(opts)
|
|
32
|
+
opts.on(*Opts::VERSION[:descr]) do
|
|
33
|
+
Opts::VERSION[:action].call
|
|
34
|
+
exit
|
|
27
35
|
end
|
|
28
36
|
end
|
|
29
37
|
end
|
data/lib/rslog/presenter.rb
CHANGED
|
@@ -5,7 +5,7 @@ require_relative 'tools/array'
|
|
|
5
5
|
|
|
6
6
|
# Class to present result in needed format
|
|
7
7
|
#
|
|
8
|
-
class Presenter
|
|
8
|
+
class Presenter < Worker
|
|
9
9
|
DECORATORS = {
|
|
10
10
|
all: {
|
|
11
11
|
title:
|
|
@@ -18,13 +18,9 @@ class Presenter
|
|
|
18
18
|
}
|
|
19
19
|
}.freeze
|
|
20
20
|
|
|
21
|
-
def initialize(container)
|
|
22
|
-
@container = container
|
|
23
|
-
end
|
|
24
|
-
|
|
25
21
|
def execute(type, formatter)
|
|
26
22
|
@type = type
|
|
27
|
-
|
|
23
|
+
container.add_message send("format_as_#{formatter}")
|
|
28
24
|
self
|
|
29
25
|
end
|
|
30
26
|
|
|
@@ -45,7 +41,7 @@ class Presenter
|
|
|
45
41
|
def format_as_text
|
|
46
42
|
[
|
|
47
43
|
title,
|
|
48
|
-
|
|
44
|
+
container.result.to_multiline_string(suffix),
|
|
49
45
|
separator
|
|
50
46
|
].join("\n")
|
|
51
47
|
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,19 +15,15 @@ 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
|
-
|
|
19
|
+
container.add_message MESSAGES[validate].call(container.validator)
|
|
24
20
|
self
|
|
25
21
|
end
|
|
26
22
|
|
|
27
23
|
private
|
|
28
24
|
|
|
29
25
|
def validate
|
|
30
|
-
return :valid if
|
|
26
|
+
return :valid if container.data.all? TEMPLATES[container.validator]
|
|
31
27
|
|
|
32
28
|
:invalid
|
|
33
29
|
end
|
data/lib/rslog/worker.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Class to hold worker functionality
|
|
4
|
+
#
|
|
5
|
+
class Worker
|
|
6
|
+
attr_reader :container
|
|
7
|
+
|
|
8
|
+
def initialize(container)
|
|
9
|
+
@container = container
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def execute
|
|
13
|
+
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}'"
|
|
14
|
+
end
|
|
15
|
+
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.12
|
|
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
|
|
@@ -28,6 +28,7 @@ files:
|
|
|
28
28
|
- lib/rslog/tools/array.rb
|
|
29
29
|
- lib/rslog/tools/hash.rb
|
|
30
30
|
- lib/rslog/validator.rb
|
|
31
|
+
- lib/rslog/worker.rb
|
|
31
32
|
homepage: https://rubygems.org/gems/rslog
|
|
32
33
|
licenses:
|
|
33
34
|
- MIT
|