ehbrs_ruby_utils 0.15.0 → 0.16.0

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: b1b4304692f05e5e54ceb820c286af557d625f2c387c88b413f79cadf23a6da2
4
- data.tar.gz: a09d3e1bd870a882c541b161cdba964de47454cac366f5dcbc1ba905246d2d7e
3
+ metadata.gz: c3ac8dd5975edfd0256392ab446b01e88a5f61887efa7bdeea37bb58df6f7333
4
+ data.tar.gz: 8a603c090ffd6c675b9a7309da25277ac708c5840688c41a6f393a7bf6045c87
5
5
  SHA512:
6
- metadata.gz: a205eed1a3e4659a457f57ad3f0b6965fc02e5a2105fe6dbac1adc9ac714798ba1db424024d34d1ba15cd9b04a367c853765bbdcbcdaa8714289e6c8035be1c1
7
- data.tar.gz: f8dbde785c72cfb1641881de9d193079bbec210f9c77f33710519ada3fc8775f29a49eb7634efe295a4b20af8ef06fdbb40323989dffb5740b1897720779ab57
6
+ metadata.gz: 15f99e542444ea740ae45d87fc2609cbf6b2142b0bdbf44740bb056934c0108459e88a75d262f8eb18fabf37575e623e7ec4e9e24a796d3a13557c55c6c192a7
7
+ data.tar.gz: 486d71cc7b0f0a62ac98c0fcc03424c01c7d43494276d24228402592262f76304bb7593a7345ff5f01aa6c7eb4a1a5a511dd143f3355f3e758a377659ee9d5fc
@@ -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.15.0'
4
+ VERSION = '0.16.0'
5
5
  end
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.15.0
4
+ version: 0.16.0
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: 2022-01-02 00:00:00.000000000 Z
11
+ date: 2022-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -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