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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe6bdea7b2a57784e35b11b4ba26542288101df7e3ca4c6a0341663a584d66ae
4
- data.tar.gz: 5063db15e2245369243465af2038ee4f12d582a2ae3a6009510250a011a22dea
3
+ metadata.gz: 843ae99c81000576196f8fb4b3cb3be0a6a529b430f02d4f205b58e9def8f61c
4
+ data.tar.gz: 0e642e1dbb538480f037e7ed33b2129b99d31441ea5c44a51a45289f2fbe4e7e
5
5
  SHA512:
6
- metadata.gz: 1d1bcdec66de44c7a554ecb3d4a9ba73190055c87293b0a257886b129462012fcd89961b4712ed0fccd2672c0fad5bb975d923532109066fdb168b8a9437965d
7
- data.tar.gz: 6277a462d27f2d771aa5b017a676409398c960b773728e5dfd8efc1e6bd03a7816fde053839a2f9129b84ab43589618bedb936c3266aa92cefb6fa7393faea2d
6
+ metadata.gz: ccce9aef8ab69e63c8162116aceb13500bd4e5cff99b318958313ab0897250e55b476cc467178ed70ff69b98d847f9593ee9f2f9d1e616403cf8e1ceb5e3ab35
7
+ data.tar.gz: 3065582ca9c1d32999faa78fc9675af66a83599222e39689b56875656cb69a715703a62e20f1910df622b776a8e6d18e730317398d2b7fd12f873739a53e9a5e
data/lib/rslog.rb CHANGED
@@ -14,7 +14,7 @@ require_relative 'rslog/opts'
14
14
  # require 'pry'
15
15
 
16
16
  class RSlog
17
- VERSION = '0.0.11'
17
+ VERSION = '0.0.12'
18
18
 
19
19
  def self.run
20
20
  Container.new.process_all
@@ -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
- @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(' ') }
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
@@ -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?(@file_name)
16
- @container.add_message 'Empty file'
18
+ if File.zero?(file_name)
19
+ container.add_message 'Empty file'
17
20
  else
18
- @container.data = File.open(@file_name, 'r').to_a
19
- @container.add_message 'Data in place'
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
- @container.add_error e
25
+ container.add_error e
23
26
  end
24
27
  end
@@ -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: @container.options)
20
+ Opts.create_opts.parse!(into: container.options)
23
21
  rescue OptionParser::InvalidOption => e
24
- @container.add_error e
22
+ container.add_error e
25
23
  end
26
24
 
27
25
  def handle_args
28
- @container.file_name = ARGV.select { |str| str =~ /.\.log|.\.txt/ }[0] || ''
29
- @container.add_error 'No file_name provided' if @container.file_name.empty?
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.on(*Opts::VERSION[:descr]) { Opts::VERSION[:action].call }
26
- opts.on(*Opts::HELP[:descr]) { Opts::HELP[:action].call(opts) }
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
@@ -20,7 +20,7 @@ class Presenter < Worker
20
20
 
21
21
  def execute(type, formatter)
22
22
  @type = type
23
- @container.add_message send("format_as_#{formatter}")
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
- @container.result.to_multiline_string(suffix),
44
+ container.result.to_multiline_string(suffix),
45
45
  separator
46
46
  ].join("\n")
47
47
  end
@@ -16,14 +16,14 @@ class Validator < Worker
16
16
  }.freeze
17
17
 
18
18
  def execute
19
- @container.add_message MESSAGES[validate].call(@container.validator)
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 @container.data.all? TEMPLATES[@container.validator]
26
+ return :valid if container.data.all? TEMPLATES[container.validator]
27
27
 
28
28
  :invalid
29
29
  end
data/lib/rslog/worker.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  # Class to hold worker functionality
4
4
  #
5
5
  class Worker
6
+ attr_reader :container
7
+
6
8
  def initialize(container)
7
9
  @container = container
8
10
  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.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Eremeev