ehbrs-tools 0.6.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/executables.rb +7 -1
  3. data/lib/ehbrs/fs.rb +9 -0
  4. data/lib/ehbrs/fs/compressed_package.rb +48 -0
  5. data/lib/ehbrs/gems.rb +37 -0
  6. data/lib/ehbrs/google.rb +9 -0
  7. data/lib/ehbrs/google/translate.rb +11 -0
  8. data/lib/ehbrs/google/translate/session.rb +61 -0
  9. data/lib/ehbrs/observers.rb +11 -0
  10. data/lib/ehbrs/observers/base.rb +64 -0
  11. data/lib/ehbrs/observers/with_persistence.rb +34 -0
  12. data/lib/ehbrs/runner/fs.rb +19 -0
  13. data/lib/ehbrs/runner/fs/used_space.rb +161 -0
  14. data/lib/ehbrs/runner/google.rb +19 -0
  15. data/lib/ehbrs/runner/google/translate.rb +92 -0
  16. data/lib/ehbrs/runner/self.rb +19 -0
  17. data/lib/ehbrs/runner/self/test.rb +30 -0
  18. data/lib/ehbrs/runner/videos/extract.rb +71 -0
  19. data/lib/ehbrs/runner/videos/series.rb +21 -0
  20. data/lib/ehbrs/runner/videos/series/rename.rb +75 -0
  21. data/lib/ehbrs/self.rb +9 -0
  22. data/lib/ehbrs/self/observers/used_space.rb +22 -0
  23. data/lib/ehbrs/self/observers/with_persistence.rb +38 -0
  24. data/lib/ehbrs/tools/version.rb +1 -1
  25. data/lib/ehbrs/user_dirs.rb +34 -0
  26. data/lib/ehbrs/vg/wii/game_file.rb +13 -0
  27. data/lib/ehbrs/videos/extract.rb +11 -0
  28. data/lib/ehbrs/videos/extract/package.rb +75 -0
  29. data/lib/ehbrs/videos/extract/package_file.rb +54 -0
  30. data/lib/ehbrs/videos/series.rb +11 -0
  31. data/lib/ehbrs/videos/series/rename.rb +13 -0
  32. data/lib/ehbrs/videos/series/rename/directory_group.rb +28 -0
  33. data/lib/ehbrs/videos/series/rename/file.rb +114 -0
  34. data/lib/ehbrs/videos/series/rename/file/basename_parser.rb +44 -0
  35. data/lib/ehbrs/videos/series/rename/file/options.rb +30 -0
  36. data/lib/ehbrs/videos/series/rename/line_result.rb +26 -0
  37. data/lib/ehbrs/videos/series/rename/line_result_group.rb +39 -0
  38. data/lib/ehbrs/videos/series/rename/results_builder.rb +32 -0
  39. data/lib/ehbrs/videos/series/rename/season_group.rb +39 -0
  40. data/vendor/aranha-selenium/Gemfile +5 -0
  41. data/vendor/aranha-selenium/aranha-selenium.gemspec +19 -0
  42. data/vendor/aranha-selenium/lib/aranha/selenium.rb +8 -0
  43. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory.rb +47 -0
  44. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/base.rb +76 -0
  45. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/chrome.rb +28 -0
  46. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox.rb +54 -0
  47. data/vendor/aranha-selenium/lib/aranha/selenium/driver_factory/firefox_auto_download_mime_types +685 -0
  48. data/vendor/aranha-selenium/lib/aranha/selenium/session.rb +78 -0
  49. data/vendor/aranha-selenium/lib/aranha/selenium/version.rb +7 -0
  50. data/vendor/aranha-selenium/spec/rubocop_check_spec.rb +7 -0
  51. data/vendor/aranha-selenium/spec/spec_helper.rb +100 -0
  52. data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +1 -1
  53. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +68 -0
  54. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs.rb +4 -12
  55. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +1 -1
  56. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +1 -1
  57. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/speaker.rb +1 -1
  58. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +2 -2
  59. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb +30 -0
  60. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp.rb +27 -8
  61. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/directory.rb +16 -0
  62. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/file.rb +34 -0
  63. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +4 -0
  64. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/lists.rb +10 -12
  65. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/symbol_list.rb +19 -0
  66. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable.rb +4 -0
  67. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb +45 -0
  68. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/common_concern.rb +10 -0
  69. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/patch.rb +1 -1
  70. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/require_sub.rb +2 -2
  71. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_present.rb +1 -1
  72. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp.rb +4 -0
  73. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/if_match.rb +16 -0
  74. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time.rb +4 -0
  75. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb +5 -0
  76. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb +25 -0
  77. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +1 -3
  78. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +45 -2
  79. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  80. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +85 -2
  81. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +42 -0
  82. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +1 -0
  83. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/docopt_runner_spec.rb +5 -5
  84. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/console/speaker_spec.rb +1 -1
  85. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/envs/executable_spec.rb +4 -0
  86. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/extname_spec.rb +18 -0
  87. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/temp_spec.rb +12 -0
  88. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/{temp.rb → temp_spec.rb} +22 -0
  89. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +32 -0
  90. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb +1 -1
  91. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb +39 -0
  92. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/hash/sym_keys_hash_spec.rb +1 -1
  93. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/if_present_spec.rb +1 -1
  94. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/template_spec.rb +1 -1
  95. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/basename_sub_spec.rb +4 -4
  96. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec.rb +19 -0
  97. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_module_a.rb +6 -0
  98. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/require_sub_spec/stubbed_not_module.rb +6 -0
  99. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/templates/searcher_spec.rb +1 -1
  100. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/yaml_spec.rb +75 -0
  101. data/vendor/eac_ruby_utils/spec/locales/pt-BR.yml +17 -0
  102. metadata +105 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96df751900aa306378007272674b8421190952ee71b133b05c10fd247397ec50
4
- data.tar.gz: 80cce53bd76f46cb08de212d227ac639345198a5c93e9fb3deedd7c214831bf9
3
+ metadata.gz: 01424b2d17105c7694679a4deb6dda7d0ab4b98f6ee0b32ed5d183bfdac33583
4
+ data.tar.gz: 271b08e6e6cf9a3868e06d1a13520030e6f1c55d167b86781f1250e92540dee7
5
5
  SHA512:
6
- metadata.gz: 538ff43fc795b7dac1aa2ab1cd24974aa8155603e0f4929c5a2a8e7186e2f546625293b6db799c73f46198114541a213bd33d9a27b819d91182e6cbf743a81a7
7
- data.tar.gz: 2292ab898b428f1afb0c490816c0756d832c2cc40fd81ef7e7aa5dfb90a11b28b257ed09de45563d12d84d915b054081db71475da169dedc26bdaab5aa1945ac
6
+ metadata.gz: bd53a0486dfec03c0d827ee8f759c5f28a490c93cb2320ea623f8a01ec5f9bdc106dd955f55114d098236b0418d96f62ab47cc2df8248b01da66bd87b3db52d8
7
+ data.tar.gz: 31dc82bd83f87cb8ea9ab4f2e8d2eac8ceba2477bf2d200156b3c01ada3794ddb673bb1d9581fc72ed9da97c3771393b701ae65f1c3c0447b9aeb344afb11d6a
@@ -15,8 +15,10 @@ module Ehbrs
15
15
  private
16
16
 
17
17
  {
18
+ '-?' => %w[rar],
19
+ '-h' => %w[unzip],
18
20
  '-version' => %w[ffmpeg ffprobe],
19
- '--version' => %w[flips wit]
21
+ '--version' => %w[flips tar wit]
20
22
  }.each do |validate_arg, commands|
21
23
  commands.each do |command|
22
24
  define_method("#{command}_uncached") do
@@ -24,6 +26,10 @@ module Ehbrs
24
26
  end
25
27
  end
26
28
  end
29
+
30
+ def sevenzip_uncached
31
+ env.executable('7z', '--help')
32
+ end
27
33
  end
28
34
  end
29
35
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module Fs
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/files/info'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Ehbrs
7
+ module Fs
8
+ class CompressedPackage < ::Avm::Files::Info
9
+ MIME_TYPES = {
10
+ 'application/zip' => :zip,
11
+ 'application/x-7z-compressed' => :sevenzip,
12
+ 'application/x-rar' => :rar,
13
+ 'application/x-tar' => :tar
14
+ }.freeze
15
+
16
+ def extract_to(target)
17
+ target = target.to_pathname
18
+ target.mkpath
19
+ sub_extract_to(target)
20
+ end
21
+
22
+ private
23
+
24
+ def sub_extract_to(target)
25
+ MIME_TYPES[content_type.mime_type].if_present do |v|
26
+ return send("#{v}_extract_command", target).execute!
27
+ end
28
+ raise "Unknown how to extract \"#{path}\" (#{content_type})"
29
+ end
30
+
31
+ def sevenzip_extract_command(target_dir)
32
+ ::Ehbrs::Executables.sevenzip.command('x', path, '-o', target_dir)
33
+ end
34
+
35
+ def tar_extract_command(target_dir)
36
+ ::Ehbrs::Executables.tar.command('-xf', path, '-C', target_dir)
37
+ end
38
+
39
+ def rar_extract_command(target_dir)
40
+ ::Ehbrs::Executables.rar.command('x', path.expand_path).chdir(target_dir)
41
+ end
42
+
43
+ def zip_extract_command(target_dir)
44
+ ::Ehbrs::Executables.unzip.command(path, '-d', target_dir)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_gems_utils/gem'
4
+
5
+ module Ehbrs
6
+ module Gems
7
+ class << self
8
+ enable_simple_cache
9
+
10
+ def app_path
11
+ ::Pathname.new('../..').expand_path(__dir__)
12
+ end
13
+
14
+ def vendor_gems_root
15
+ app_path.join('vendor')
16
+ end
17
+
18
+ private
19
+
20
+ def app_uncached
21
+ ::EacRubyGemsUtils::Gem.new(app_path)
22
+ end
23
+
24
+ def all_uncached
25
+ vendor_gems + [app]
26
+ end
27
+
28
+ def vendor_gems_uncached
29
+ r = []
30
+ vendor_gems_root.each_child.each do |child|
31
+ r << ::EacRubyGemsUtils::Gem.new(child) if child.directory?
32
+ end
33
+ r
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module Google
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module Google
7
+ module Translate
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/selenium/session'
4
+
5
+ module Ehbrs
6
+ module Google
7
+ module Translate
8
+ class Session
9
+ START_URL = 'https://translate.google.com.br/#view=home&op=docs&sl=en&tl=pt'
10
+ CLOSE_POPUP_CSS = '.dismiss-button'
11
+ FILE_INPUT_XPATH = '//*[@id = "tlid-file-input"]'
12
+ SUBMIT_XPATH = '//form[@action="//translate.googleusercontent.com/translate_f"]' \
13
+ '//input[@type="submit"]'
14
+ RESULT_XPATHS = [
15
+ '//script[contains(@src, "https://translate.google.com/translate_a")]',
16
+ '/html/body/pre'
17
+ ].freeze
18
+
19
+ attr_reader :sub
20
+
21
+ def initialize
22
+ @sub = ::Aranha::Selenium::Session.new
23
+ end
24
+
25
+ def translate(source_document_path)
26
+ go_to_upload_form
27
+ input_file(source_document_path)
28
+ close_changes_alert_popup
29
+ click_on_translate_button
30
+ wait_for_load_translation
31
+ sub.current_source
32
+ end
33
+
34
+ private
35
+
36
+ def go_to_upload_form
37
+ sub.navigate.to START_URL
38
+ sub.wait_for_element(xpath: FILE_INPUT_XPATH)
39
+ end
40
+
41
+ def input_file(source_document_path)
42
+ sub.find_element(xpath: FILE_INPUT_XPATH).send_keys(source_document_path)
43
+ end
44
+
45
+ def click_on_translate_button
46
+ sub.wait_for_click(xpath: SUBMIT_XPATH)
47
+ end
48
+
49
+ def close_changes_alert_popup
50
+ sub.wait_for_click(css: CLOSE_POPUP_CSS)
51
+ end
52
+
53
+ def wait_for_load_translation
54
+ sub.wait.until do
55
+ RESULT_XPATHS.any? { |xpath| sub.find_elements(xpath: xpath).size.positive? }
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module Fs
7
+ module Observers
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ostruct'
5
+
6
+ module Ehbrs
7
+ module Observers
8
+ class Base
9
+ include ::EacRubyUtils::Listable
10
+
11
+ lists.add_string :blank_value, :add, :ignore, :raise
12
+
13
+ attr_reader :records, :blank_value, :last_check_time
14
+
15
+ common_constructor :options, default: [{}] do
16
+ @records = options[:records] || []
17
+ @blank_value = options[:blank_value].if_present(BLANK_VALUE_ADD) do |v|
18
+ v = v.to_s
19
+ ::Ehbrs::Observers::Base.lists.blank_value.value_validate!(v)
20
+ v
21
+ end
22
+ end
23
+
24
+ def check(value, date = ::Time.zone.now)
25
+ @last_check_time = date
26
+ send("check_with_blank_value_#{blank_value}", value, date)
27
+ end
28
+
29
+ def changing_value?(value)
30
+ records.if_present(true) do
31
+ last_value.if_present(value.present?) { |v| v != value }
32
+ end
33
+ end
34
+
35
+ def last_change_time
36
+ records.last.if_present(&:time)
37
+ end
38
+
39
+ def last_value
40
+ records.last.if_present(&:value)
41
+ end
42
+
43
+ private
44
+
45
+ def check_with_blank_value_add(value, time)
46
+ return false unless changing_value?(value)
47
+
48
+ records << ::OpenStruct.new(value: value, time: time)
49
+ true
50
+ end
51
+
52
+ def check_with_blank_value_ignore(value, date)
53
+ return false if value.blank? ? false : check_with_blank_value_add(value, date)
54
+ end
55
+
56
+ def check_with_blank_value_raise(value, date)
57
+ raise(::ArgumentError, "Blank value checked (Value: #{value}, Class: #{value.class})") if
58
+ value.blank?
59
+
60
+ check_with_blank_value_add(value, date)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/observers/base'
5
+
6
+ module Ehbrs
7
+ module Observers
8
+ class WithPersistence < ::Ehbrs::Observers::Base
9
+ attr_reader :path
10
+
11
+ def initialize(path, options = {})
12
+ super(options)
13
+ @path = path.to_pathname
14
+ load
15
+ end
16
+
17
+ def check(value, date = ::Time.zone.now)
18
+ save if super(value, date)
19
+ end
20
+
21
+ def load
22
+ save unless path.exist?
23
+ data = ::YAML.load_file(path.to_path)
24
+ @records = data.fetch(:records).map { |h| ::OpenStruct.new(h) }
25
+ @last_check_time = data.fetch(:last_check_time)
26
+ end
27
+
28
+ def save
29
+ path.parent.mkpath
30
+ path.write({ records: records.map(&:to_h), last_check_time: last_check_time }.to_yaml)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+
7
+ module Ehbrs
8
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
9
+ class Fs < ::EacRubyUtils::Console::DocoptRunner
10
+ include ::EacCli::DefaultRunner
11
+ require_sub __FILE__
12
+
13
+ runner_definition do
14
+ desc 'Ferramentas para o sistema de arquivos.'
15
+ subcommands
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,161 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs/self/observers/used_space'
4
+ require 'filesize'
5
+
6
+ module Ehbrs
7
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
8
+ class Fs < ::EacRubyUtils::Console::DocoptRunner
9
+ class UsedSpace < ::EacRubyUtils::Console::DocoptRunner
10
+ include ::EacCli::DefaultRunner
11
+
12
+ runner_definition do
13
+ desc 'Verifica e anota alterações de espaço usado de um objeto de sistema de arquivos.'
14
+ bool_opt '-c', '--check', 'Anota o espaço em disco.'
15
+ bool_opt '-v', '--verbose', 'Verbose.'
16
+ pos_arg :paths, repeat: true
17
+ end
18
+
19
+ def run
20
+ root_banner
21
+ paths.each(&:run)
22
+ end
23
+
24
+ def check?
25
+ options.fetch('--check')
26
+ end
27
+
28
+ private
29
+
30
+ def root_banner
31
+ return unless verbose?
32
+
33
+ infov 'Paths', paths.count
34
+ infov 'Check?', check?
35
+ infov 'Verbose?', verbose?
36
+ end
37
+
38
+ def path_class
39
+ verbose? ? PathVerbose : PathUnverbose
40
+ end
41
+
42
+ def paths_uncached
43
+ options.fetch('<paths>').map { |path| path_class.new(self, path) }
44
+ end
45
+
46
+ def verbose?
47
+ options.fetch('--verbose')
48
+ end
49
+
50
+ class PathBase
51
+ enable_simple_cache
52
+ enable_console_speaker
53
+ common_constructor :runner, :path do
54
+ self.path = path.to_pathname
55
+ end
56
+
57
+ private
58
+
59
+ def last_change_time
60
+ time_label(observer.observer.last_change_time)
61
+ end
62
+
63
+ def last_check
64
+ time_label(observer.observer.last_check_time)
65
+ end
66
+
67
+ def last_value
68
+ bytes_label(observer.observer.last_value)
69
+ end
70
+
71
+ def current_value
72
+ bytes_label(observer.current_value).colorize(
73
+ observer.changing_value? ? :green : :light_black
74
+ )
75
+ end
76
+
77
+ def changing_value?
78
+ changing_label(observer.changing_value?)
79
+ end
80
+
81
+ def observer_uncached
82
+ ::Ehbrs::Self::Observers::UsedSpace.new(path)
83
+ end
84
+
85
+ def changing_label(bool)
86
+ bool.to_s.colorize(bool ? :green : :light_black)
87
+ end
88
+
89
+ def time_label(time)
90
+ time.if_present('-', &:to_s)
91
+ end
92
+ end
93
+
94
+ class PathVerbose < PathBase
95
+ def run
96
+ infom path.to_s
97
+ on_speaker_node do |node|
98
+ node.stderr_line_prefix = ' '
99
+ banner
100
+ check
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ def banner
107
+ { 'Path' => observer.path,
108
+ 'Persistence path' => observer.persistence_path,
109
+ 'Last check' => last_check,
110
+ 'Last change' => last_change_time,
111
+ 'Last value' => last_value,
112
+ 'Current value' => current_value,
113
+ 'Changing?' => changing_value? }.each do |k, v|
114
+ infov k, v
115
+ end
116
+ end
117
+
118
+ def check
119
+ return unless runner.check?
120
+
121
+ infom 'Checking...'
122
+ if observer.check_current_value
123
+ success 'A new value was recorded'
124
+ else
125
+ info 'No new value was recorded'
126
+ end
127
+ end
128
+
129
+ def bytes_label(number)
130
+ number.if_present('-') { |v| "#{v} (#{::Filesize.from("#{v} B").pretty})" }
131
+ end
132
+ end
133
+
134
+ class PathUnverbose < PathBase
135
+ def run
136
+ self.puts output_line
137
+ end
138
+
139
+ def output_line
140
+ [path.to_s.cyan, last_change_time, last_value, current_value, check_result]
141
+ .reject(&:blank?).join('|')
142
+ end
143
+
144
+ def check_result
145
+ return nil unless runner.check?
146
+
147
+ observer.check_current_value ? 'Recorded'.green : 'Unchanged'.light_black
148
+ end
149
+
150
+ def bytes_label(number)
151
+ number.if_present('-') { |v| ::Filesize.from("#{v} B").pretty }
152
+ end
153
+
154
+ def time_label(time)
155
+ time.if_present('-') { |t| t.strftime('%d/%m/%y %H:%M') }
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end