rslog 0.0.11 → 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 +1 -1
- data/lib/rslog/data_parser.rb +8 -8
- data/lib/rslog/extractor.rb +9 -6
- data/lib/rslog/input_parser.rb +4 -6
- data/lib/rslog/opts.rb +12 -4
- data/lib/rslog/presenter.rb +2 -2
- data/lib/rslog/validator.rb +2 -2
- data/lib/rslog/worker.rb +2 -0
- 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: 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
data/lib/rslog/data_parser.rb
CHANGED
|
@@ -9,14 +9,14 @@ class DataParser < Worker
|
|
|
9
9
|
# type = :count (default) -> just count in groups
|
|
10
10
|
# type = :uniq -> uniq entries in groups
|
|
11
11
|
def execute(type)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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(' ') }
|
|
20
20
|
self
|
|
21
21
|
end
|
|
22
22
|
end
|
data/lib/rslog/extractor.rb
CHANGED
|
@@ -4,21 +4,24 @@
|
|
|
4
4
|
#
|
|
5
5
|
class Extractor < Worker
|
|
6
6
|
def execute
|
|
7
|
-
@file_name = @container.file_name
|
|
8
7
|
check
|
|
9
8
|
self
|
|
10
9
|
end
|
|
11
10
|
|
|
12
11
|
private
|
|
13
12
|
|
|
13
|
+
def file_name
|
|
14
|
+
container.file_name
|
|
15
|
+
end
|
|
16
|
+
|
|
14
17
|
def check
|
|
15
|
-
if File.zero?(
|
|
16
|
-
|
|
18
|
+
if File.zero?(file_name)
|
|
19
|
+
container.add_message 'Empty file'
|
|
17
20
|
else
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
container.data = File.open(file_name, 'r').to_a
|
|
22
|
+
container.add_message 'Data in place'
|
|
20
23
|
end
|
|
21
24
|
rescue StandardError => e
|
|
22
|
-
|
|
25
|
+
container.add_error e
|
|
23
26
|
end
|
|
24
27
|
end
|
data/lib/rslog/input_parser.rb
CHANGED
|
@@ -16,16 +16,14 @@ class InputParser < Worker
|
|
|
16
16
|
|
|
17
17
|
private
|
|
18
18
|
|
|
19
|
-
attr_accessor :opts
|
|
20
|
-
|
|
21
19
|
def handle_opts
|
|
22
|
-
Opts.create_opts.parse!(into:
|
|
20
|
+
Opts.create_opts.parse!(into: container.options)
|
|
23
21
|
rescue OptionParser::InvalidOption => e
|
|
24
|
-
|
|
22
|
+
container.add_error e
|
|
25
23
|
end
|
|
26
24
|
|
|
27
25
|
def handle_args
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
container.file_name = ARGV.select { |str| str =~ /.\.log|.\.txt/ }[0] || ''
|
|
27
|
+
container.add_error 'No file_name provided' if container.file_name.empty?
|
|
30
28
|
end
|
|
31
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
|
@@ -20,7 +20,7 @@ class Presenter < Worker
|
|
|
20
20
|
|
|
21
21
|
def execute(type, formatter)
|
|
22
22
|
@type = type
|
|
23
|
-
|
|
23
|
+
container.add_message send("format_as_#{formatter}")
|
|
24
24
|
self
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -41,7 +41,7 @@ class Presenter < Worker
|
|
|
41
41
|
def format_as_text
|
|
42
42
|
[
|
|
43
43
|
title,
|
|
44
|
-
|
|
44
|
+
container.result.to_multiline_string(suffix),
|
|
45
45
|
separator
|
|
46
46
|
].join("\n")
|
|
47
47
|
end
|
data/lib/rslog/validator.rb
CHANGED
|
@@ -16,14 +16,14 @@ class Validator < Worker
|
|
|
16
16
|
}.freeze
|
|
17
17
|
|
|
18
18
|
def execute
|
|
19
|
-
|
|
19
|
+
container.add_message MESSAGES[validate].call(container.validator)
|
|
20
20
|
self
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
private
|
|
24
24
|
|
|
25
25
|
def validate
|
|
26
|
-
return :valid if
|
|
26
|
+
return :valid if container.data.all? TEMPLATES[container.validator]
|
|
27
27
|
|
|
28
28
|
:invalid
|
|
29
29
|
end
|
data/lib/rslog/worker.rb
CHANGED