ehbrs_ruby_utils 0.13.0 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5aaed3c96601c1f0e58b967d6329f6f78b9e4c4b71af95a938c7315cceaf33dd
4
- data.tar.gz: 07aa64f3b9f8681a497e803fd6a5dd750efb8d334953b82e51ec56b96835a36b
3
+ metadata.gz: 248e8e66248825fd3c183caa3a5f24d0887ff5aff0522fcd4e5cabe270881b09
4
+ data.tar.gz: fc395fe779b480bd8d3ce45f7c87a95a322478024e810a35887e2a625f05d211
5
5
  SHA512:
6
- metadata.gz: fb8e0db71d2926730c2ac6850769bc5f93965a42480c8fabfdaaeaeef65c5317bc5bb445e38aee185fe226dcd46c6dcc0f9287ee1a3e82b576d7e2239cb173e5
7
- data.tar.gz: 07e0d381377ba0678607414120e349211a1e09bd5ba02ac71acb4e069da6e33ca202eb383b0dc7d18306516cd987b24213c9a821e140197008743b6a09bc699c
6
+ metadata.gz: 2f0b5100010b034b30c5986f5f24d92b8ff77ed1ddbd6984f6600c2089746b30bf967ef5c6958df8cdd7b089204f871aa3ef79c31f5b2b58c35dcc66746c4c0e
7
+ data.tar.gz: ffc7fd0468c1c278b3e6003f149b3cbd9e215fcbfcddbb39f3666b0b10eef8be77da78f674938fa5be8f1745f4dadb9c3329886abfca767a4d95a62572a75494
@@ -26,7 +26,7 @@ module EhbrsRubyUtils
26
26
  end
27
27
 
28
28
  def lyrics_cached?
29
- lyrics_cache.cached?
29
+ lyrics_cache.stored?
30
30
  end
31
31
 
32
32
  def cached_lyrics
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/music/ous/artist'
5
+ require 'ehbrs_ruby_utils/music/ous/node'
6
+
7
+ module EhbrsRubyUtils
8
+ module Music
9
+ module Ous
10
+ class Album < ::EhbrsRubyUtils::Music::Ous::Node
11
+ include ::Comparable
12
+
13
+ def <=>(other)
14
+ to_a <=> other.to_a
15
+ end
16
+
17
+ def to_a
18
+ [language, category.name, artist.name, name]
19
+ end
20
+
21
+ def to_spreader_t1_path
22
+ to_a
23
+ end
24
+
25
+ def to_label
26
+ (to_a + [id]).map(&:light_white).join(' | '.blue)
27
+ end
28
+
29
+ delegate :to_path, to: :path
30
+
31
+ def id
32
+ [artist.name, name].join('_').variableize
33
+ end
34
+
35
+ # @return [EhbrsRubyUtils::Music::Ous::Artist]
36
+ def artist
37
+ parent_node
38
+ end
39
+
40
+ def category
41
+ artist.parent_node
42
+ end
43
+
44
+ def parent_node_class
45
+ ::EhbrsRubyUtils::Music::Ous::Artist
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/music/ous/category'
5
+ require 'ehbrs_ruby_utils/music/ous/node'
6
+
7
+ module EhbrsRubyUtils
8
+ module Music
9
+ module Ous
10
+ class Artist < ::EhbrsRubyUtils::Music::Ous::Node
11
+ def parent_node_class
12
+ ::EhbrsRubyUtils::Music::Ous::Category
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/music/ous/node'
5
+
6
+ module EhbrsRubyUtils
7
+ module Music
8
+ module Ous
9
+ class Category < ::EhbrsRubyUtils::Music::Ous::Node
10
+ def parent_node_class
11
+ nil
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Music
7
+ module Ous
8
+ class Node
9
+ DEFAULT_LANGUAGE = 'unk'
10
+ LANGUAGE_FILE_BASENAME = '.language'
11
+
12
+ enable_simple_cache
13
+ common_constructor :path do
14
+ self.path = path.to_pathname.expand_path
15
+ end
16
+
17
+ def name
18
+ real_path.basename.to_s
19
+ end
20
+
21
+ def language
22
+ self_language || parent_language || DEFAULT_LANGUAGE
23
+ end
24
+
25
+ def language_file
26
+ path.join(LANGUAGE_FILE_BASENAME)
27
+ end
28
+
29
+ def parent_language
30
+ parent_node.if_present(&:language)
31
+ end
32
+
33
+ def real_path
34
+ path.readlink_r
35
+ end
36
+
37
+ def self_language
38
+ language_file.if_exist('', &:read).strip.presence
39
+ end
40
+
41
+ def to_s
42
+ name
43
+ end
44
+
45
+ private
46
+
47
+ def parent_node_uncached
48
+ parent_node_class.if_present { |v| v.new(real_path.parent) }
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ class SpreaderT1
7
+ module BaseLevel
8
+ extend ::Comparable
9
+
10
+ def <=>(other)
11
+ s = remaining_f <=> other.remaining_f
12
+ return s unless s.zero?
13
+
14
+ s = total_i <=> other.total_i
15
+ return s unless s.zero?
16
+
17
+ other.label <=> label
18
+ end
19
+
20
+ def remaining?
21
+ remaining_i.positive?
22
+ end
23
+
24
+ def remaining_f
25
+ remaining_i.to_f / total_i
26
+ end
27
+
28
+ def remaining_fs
29
+ ((remaining_f * 1000).round / 10.0).to_s + '%'
30
+ end
31
+
32
+ def debugs
33
+ [label, remaining_fs, total_i].join(' / ')
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/spreader_t1/base_level'
5
+ require 'ehbrs_ruby_utils/spreader_t1/item_level'
6
+
7
+ module EhbrsRubyUtils
8
+ class SpreaderT1
9
+ class GroupLevel
10
+ include ::EhbrsRubyUtils::SpreaderT1::BaseLevel
11
+ enable_simple_cache
12
+
13
+ common_constructor :label
14
+
15
+ def push(path, item)
16
+ child_path = path.dup
17
+ current = child_path.shift
18
+ if child_path.any?
19
+ push_group_level(current, child_path, item)
20
+ else
21
+ push_item_level(current, item)
22
+ end
23
+ end
24
+
25
+ def pop
26
+ children.values.max.pop
27
+ end
28
+
29
+ def pop_all
30
+ r = []
31
+ while remaining?; r << pop; end
32
+ r
33
+ end
34
+
35
+ def remaining_i
36
+ children.values.inject(0) { |a, e| a + e.remaining_i }
37
+ end
38
+
39
+ def total_i
40
+ children.values.inject(0) { |a, e| a + e.total_i }
41
+ end
42
+
43
+ private
44
+
45
+ attr_accessor :item
46
+
47
+ def push_group_level(current, child_path, item)
48
+ children[current] ||= self.class.new(current)
49
+ children[current].push(child_path, item)
50
+ end
51
+
52
+ def children
53
+ @children ||= {}
54
+ end
55
+
56
+ def push_item_level(current, item)
57
+ raise "Key \"#{current}\" already used" if children[current].present?
58
+
59
+ children[current] = ::EhbrsRubyUtils::SpreaderT1::ItemLevel.new(item)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/spreader_t1/base_level'
5
+
6
+ module EhbrsRubyUtils
7
+ class SpreaderT1
8
+ class ItemLevel
9
+ include ::EhbrsRubyUtils::SpreaderT1::BaseLevel
10
+
11
+ common_constructor :item do
12
+ self.removed = false
13
+ end
14
+
15
+ def label
16
+ item.to_s
17
+ end
18
+
19
+ def pop
20
+ raise 'Item already removed' if removed?
21
+
22
+ self.removed = true
23
+ item
24
+ end
25
+
26
+ def remaining_i
27
+ removed? ? 0 : 1
28
+ end
29
+
30
+ def removed?
31
+ @removed
32
+ end
33
+
34
+ def total_i
35
+ 1
36
+ end
37
+
38
+ private
39
+
40
+ attr_writer :removed
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ class SpreaderT1
7
+ require_sub __FILE__
8
+ common_constructor :items
9
+
10
+ # @return [Array]
11
+ def result
12
+ root_level = ::EhbrsRubyUtils::SpreaderT1::GroupLevel.new('ROOT')
13
+ items.each { |item| root_level.push(item.to_spreader_t1_path, item) }
14
+ root_level.pop_all
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.13.0'
4
+ VERSION = '0.16.1'
5
5
  end
@@ -53,6 +53,10 @@ module EhbrsRubyUtils
53
53
  tags[:language]
54
54
  end
55
55
 
56
+ def language_with_title
57
+ [language, title].reject(&:blank?).if_present { |v| v.join('_').variableize }
58
+ end
59
+
56
60
  def title
57
61
  tags[:title]
58
62
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'avm/result'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EhbrsRubyUtils
8
+ module WebUtils
9
+ class Instance < ::Avm::Instances::Base
10
+ class Finances
11
+ class Bills
12
+ class Consume
13
+ class File
14
+ enable_speaker
15
+ enable_simple_cache
16
+ common_constructor(:bills, :path) { perform }
17
+ delegate :instance, to: :bills
18
+
19
+ protected
20
+
21
+ def perform
22
+ infov 'Relative path', relative_path
23
+ process_response
24
+ end
25
+
26
+ def relative_path
27
+ path.relative_path_from(bills.pending_directory.to_path)
28
+ end
29
+
30
+ def process_response
31
+ if response_status_result.success?
32
+ move_to_registered
33
+ else
34
+ warn(" * Retornou com status de erro:\n\n#{response.body}")
35
+ end
36
+ infov ' * Response status', response_status_result.label
37
+ end
38
+
39
+ def move_to_registered
40
+ ::FileUtils.mkdir_p(::File.dirname(target_path))
41
+ ::File.rename(path, target_path)
42
+ end
43
+
44
+ def target_path
45
+ ::File.join(bills.registered_directory, relative_path)
46
+ end
47
+
48
+ def response_uncached
49
+ bills.instance.http_request(
50
+ '/finances/file_imports',
51
+ method: :post,
52
+ body: {
53
+ 'record[file]' => ::File.new(path)
54
+ },
55
+ header: {
56
+ 'Accept' => 'application/json'
57
+ }
58
+ )
59
+ end
60
+
61
+ def response_status_result
62
+ ::Avm::Result.success_or_error(
63
+ response.status.to_s.match?(/\A2\d{2}\z/),
64
+ response.status
65
+ )
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module WebUtils
8
+ class Instance < ::Avm::Instances::Base
9
+ class Finances
10
+ class Bills
11
+ class Consume
12
+ require_sub __FILE__
13
+ common_constructor(:bills)
14
+ delegate :instance, :pending_directory, :registered_directory, to: :bills
15
+
16
+ def perform
17
+ bills.pending_directory.glob('**/*').each do |path|
18
+ next unless path.file?
19
+
20
+ ::EhbrsRubyUtils::WebUtils::Instance::Finances::Bills::Consume::File.new(self, path)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module WebUtils
8
+ class Instance < ::Avm::Instances::Base
9
+ class Finances
10
+ class Bills
11
+ require_sub __FILE__
12
+ common_constructor :finances
13
+ delegate :instance, to: :finances
14
+
15
+ # @return [Pathname]
16
+ def bills_directory(suffix)
17
+ instance.read_entry('finances.bills.directory').to_pathname.join(suffix)
18
+ end
19
+
20
+ # @return [EhbrsRubyUtils::WebUtils::Instance::Finances::Bills::Consume]
21
+ def consume
22
+ ::EhbrsRubyUtils::WebUtils::Instance::Finances::Bills::Consume.new(self)
23
+ end
24
+
25
+ # @return [Pathname]
26
+ def pending_directory
27
+ bills_directory('pending')
28
+ end
29
+
30
+ # @return [Pathname]
31
+ def registered_directory
32
+ bills_directory('registered')
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module WebUtils
8
+ class Instance < ::Avm::Instances::Base
9
+ class Finances
10
+ require_sub __FILE__
11
+ enable_simple_cache
12
+ common_constructor :instance
13
+
14
+ private
15
+
16
+ def bills_uncached
17
+ ::EhbrsRubyUtils::WebUtils::Instance::Finances::Bills.new(self)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -7,8 +7,14 @@ require 'httpclient'
7
7
  module EhbrsRubyUtils
8
8
  module WebUtils
9
9
  class Instance < ::Avm::Instances::Base
10
+ require_sub __FILE__
11
+
12
+ def finances
13
+ @finances ||= ::EhbrsRubyUtils::WebUtils::Instance::Finances.new(self)
14
+ end
15
+
10
16
  def root_url
11
- read_entry(:url)
17
+ read_entry(::Avm::Instances::EntryKeys::WEB_URL)
12
18
  end
13
19
 
14
20
  def resource_url(resource_url_suffix)
@@ -7,7 +7,7 @@ RSpec.describe ::EhbrsRubyUtils::Videos::Stream do
7
7
 
8
8
  def source_data(source_file)
9
9
  instance = described_class.new(::YAML.load_file(source_file))
10
- %w[codec_name codec_long_name codec_type index language title]
10
+ %w[codec_name codec_long_name codec_type index language language_with_title title]
11
11
  .map { |k| [k.to_sym, instance.send(k)] }.sort.to_h
12
12
  end
13
13
  end
@@ -4,4 +4,5 @@
4
4
  :codec_type: :attachment
5
5
  :index: 19
6
6
  :language:
7
+ :language_with_title:
7
8
  :title:
@@ -4,4 +4,5 @@
4
4
  :codec_type: :audio
5
5
  :index: 18
6
6
  :language: jpn
7
+ :language_with_title: jpn_animerg_tenshi_no_tamago_1080p_scavvykid
7
8
  :title: "[AnimeRG] Tenshi No Tamago [1080p] [ScavvyKiD]"
@@ -4,4 +4,5 @@
4
4
  :codec_type: :subtitle
5
5
  :index: 0
6
6
  :language: fre
7
+ :language_with_title: fre_french_subs
7
8
  :title: French Subs
@@ -4,4 +4,5 @@
4
4
  :codec_type: :video
5
5
  :index: 17
6
6
  :language: eng
7
+ :language_with_title: eng_animerg_tenshi_no_tamago_1080p_scavvykid
7
8
  :title: "[AnimeRG] Tenshi No Tamago [1080p] [ScavvyKiD]"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehbrs_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-17 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -56,14 +56,14 @@ dependencies:
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '0.5'
59
+ version: '0.10'
60
60
  type: :runtime
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: '0.5'
66
+ version: '0.10'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: eac_ruby_utils
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -176,9 +176,17 @@ files:
176
176
  - lib/ehbrs_ruby_utils/music/lyrics_book/album.rb
177
177
  - lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb
178
178
  - lib/ehbrs_ruby_utils/music/lyrics_book/song.rb
179
+ - lib/ehbrs_ruby_utils/music/ous/album.rb
180
+ - lib/ehbrs_ruby_utils/music/ous/artist.rb
181
+ - lib/ehbrs_ruby_utils/music/ous/category.rb
182
+ - lib/ehbrs_ruby_utils/music/ous/node.rb
179
183
  - lib/ehbrs_ruby_utils/patches.rb
180
184
  - lib/ehbrs_ruby_utils/patches/object.rb
181
185
  - lib/ehbrs_ruby_utils/patches/object/template.rb
186
+ - lib/ehbrs_ruby_utils/spreader_t1.rb
187
+ - lib/ehbrs_ruby_utils/spreader_t1/base_level.rb
188
+ - lib/ehbrs_ruby_utils/spreader_t1/group_level.rb
189
+ - lib/ehbrs_ruby_utils/spreader_t1/item_level.rb
182
190
  - lib/ehbrs_ruby_utils/version.rb
183
191
  - lib/ehbrs_ruby_utils/videos.rb
184
192
  - lib/ehbrs_ruby_utils/videos/container.rb
@@ -188,6 +196,10 @@ files:
188
196
  - lib/ehbrs_ruby_utils/videos/stream.rb
189
197
  - lib/ehbrs_ruby_utils/web_utils.rb
190
198
  - lib/ehbrs_ruby_utils/web_utils/instance.rb
199
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances.rb
200
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances/bills.rb
201
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances/bills/consume.rb
202
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances/bills/consume/file.rb
191
203
  - lib/ehbrs_ruby_utils/web_utils/videos.rb
192
204
  - lib/ehbrs_ruby_utils/web_utils/videos/file.rb
193
205
  - lib/ehbrs_ruby_utils/web_utils/videos/file/rename.rb