rslog 0.0.8 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 327a6ca58c14f9e3a6353be6b4ef8103b42b59d7d31b426d525dde7e3bb114cd
4
- data.tar.gz: f24b4b26f9018bf44888fe48d1608c5de8df866a6072f551d39a27b79c4715cf
3
+ metadata.gz: 6ce0368ae8830da116ff45bb102f0156e0ff0c320f57ddb0ba133efa019b7460
4
+ data.tar.gz: b12a734d292403f0dfabe560e22e170ec1f4e72d9a07227f80291d5aeb72c51b
5
5
  SHA512:
6
- metadata.gz: a76b136d798fefbc27b1d34943fa5325872b79c1b2b0851c96bc90b2899c1208ad3cd6f103b13b998cb78ee34f47f551309a0f23c6792156a70a11d81f56d4a6
7
- data.tar.gz: fa19a42467be47c2923cc8ac2cee2300881fef2a81994ea1f76f13c5ffaa8750045f9268a334f100f0d26c0d349c40694d563c6963997517f4c6f6d3366a8c1d
6
+ metadata.gz: 277bec231152641cbd79ad42f7737f7bccf69e2abb5d804d0a976c42d6a4f353fac5761555e7a662bb7767eb6c7ad7499e2716ea9305e343b2c7b542178a3540
7
+ data.tar.gz: 8b245fc399ac058b0cad266fd1684cbfa76136d8b2c02e6bc1c088441482758b54e8a5a25d00f2de50ce9889ad42a3ba02ba92ba85594ab1aaa32680e1e59896
data/lib/rslog.rb CHANGED
@@ -13,7 +13,7 @@ require_relative 'rslog/opts'
13
13
  # require 'pry'
14
14
 
15
15
  class RSlog
16
- VERSION = '0.0.8'
16
+ VERSION = '0.0.9'
17
17
 
18
18
  def self.run
19
19
  Container.new.process_all
@@ -2,17 +2,14 @@
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
8
  # Class to parse data from given array
8
9
  #
9
- class DataParser
10
+ class DataParser < Worker
10
11
  # type = :count (default) -> just count in groups
11
12
  # type = :uniq -> uniq entries in groups
12
- def initialize(container)
13
- @container = container
14
- end
15
-
16
13
  def execute(type)
17
14
  @container.result =
18
15
  @container.data
@@ -1,16 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'container'
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
@@ -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,7 +20,7 @@ class InputParser
24
20
  attr_accessor :opts
25
21
 
26
22
  def handle_opts
27
- @opts.parse!(into: @container.options)
23
+ Opts.create_opts.parse!(into: @container.options)
28
24
  rescue OptionParser::InvalidOption => e
29
25
  @container.add_error e
30
26
  end
@@ -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,13 +19,9 @@ 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.messages << send("format_as_#{formatter}")
24
+ @container.add_message send("format_as_#{formatter}")
28
25
  self
29
26
  end
30
27
 
@@ -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,10 +15,6 @@ 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
@@ -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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rslog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Eremeev
@@ -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