ehbrs_ruby_utils 0.10.0 → 0.12.2

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: e525be69cfe63696e72dc2184618e53ab5d092cb330ea999a0cc7c1593b59a09
4
- data.tar.gz: 3bc91b8b5660eef3fd427f3795f4c7191b4bc1f253cd6cbad4d84b59686997d0
3
+ metadata.gz: 54140d1a239396122b8554925ae4a09d63baa410518ed9c01dad2af0095dd1f5
4
+ data.tar.gz: 22068ffc417f96c492fce8681727556acc12a8e92109492daa6f6ea6d957dcb3
5
5
  SHA512:
6
- metadata.gz: 8dba5f9914093130cc606c99ed44e5dc88967dc7423cd8843d89111636ccd70d7a2570adfa087d5c6148347ffd03dfbc9efda4b107c88e7b1dac0fde2485f96b
7
- data.tar.gz: 0dbfef1d8c97cc3179789d9fcc3c1dffcaad87154e697d5a04d514c2cdb737bbb4350702e3f9846cb8057f18238bf7907acfd073c1372097d77b63e04ab4507d
6
+ metadata.gz: 7f7178cf59de3f899897637b64598c81a842e0a3fb0029e411395a74049cf9a4f9aaaed7e4fba2a59fe7677b113de5d4e2543cdb2811eea018fb1fcdeb23adb0
7
+ data.tar.gz: d80204e45d77da1402fd1ed65298952645c1ef22e2ae136ebda3086be5681e5861078c6dafbfb2b8832532bc5d853d0b609ad95dc5cceeb2cb03dfa2fca49c7f
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/patches'
5
+ require 'ehbrs_ruby_utils/patches'
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_fs/file_info'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module Fs
8
+ class CompressedPackage < ::EacFs::FileInfo
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,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/fs/selected/build_file'
5
+
6
+ module EhbrsRubyUtils
7
+ module Fs
8
+ class Selected
9
+ class Build
10
+ DEFAULT_TARGET_BASENAME_PROC = ::Proc.new { |path| path.basename.to_path }
11
+
12
+ attr_reader :selected, :target_dir, :target_basename_proc
13
+
14
+ def initialize(selected, target_dir, &target_basename_proc)
15
+ @selected = selected
16
+ @target_dir = target_dir.to_pathname
17
+ @target_basename_proc = target_basename_proc.presence || DEFAULT_TARGET_BASENAME_PROC
18
+ end
19
+
20
+ def perform
21
+ clear_target_dir
22
+ link_selected_found
23
+ end
24
+
25
+ private
26
+
27
+ def clear_target_dir
28
+ target_dir.children.each do |c|
29
+ c.unlink if c.symlink? && c.directory?
30
+ end
31
+ end
32
+
33
+ def link_selected_found
34
+ selected.found.each do |found|
35
+ ::EhbrsRubyUtils::Fs::Selected::BuildFile.new(self, found).perform
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Fs
7
+ class Selected
8
+ class BuildFile
9
+ common_constructor :build, :path do
10
+ self.path = path.to_pathname
11
+ end
12
+
13
+ def perform
14
+ target_path.make_symlink(path)
15
+ end
16
+
17
+ def target_path
18
+ build.target_dir.join(target_basename)
19
+ end
20
+
21
+ def target_basename
22
+ build.target_basename_proc.call(path)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_fs/traverser'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module Fs
8
+ class Selected
9
+ require_sub __FILE__
10
+ DEFAULT_FILENAME = '.selected'
11
+
12
+ enable_listable
13
+ enable_simple_cache
14
+ lists.add_symbol :option, :filename, :target_name_builder
15
+ common_constructor :root_path, :options, default: [{}] do
16
+ self.root_path = root_path.to_pathname
17
+ self.options = self.class.lists.option.hash_keys_validate!(options)
18
+ end
19
+
20
+ def build(target_dir, &directory_target_basename)
21
+ ::EhbrsRubyUtils::Fs::Selected::Build.new(self, target_dir, &directory_target_basename)
22
+ end
23
+
24
+ def filename
25
+ options[OPTION_FILENAME].if_present(DEFAULT_FILENAME)
26
+ end
27
+
28
+ private
29
+
30
+ # @return [Pathname]
31
+ def found_uncached
32
+ r = []
33
+ ft = ::EacFs::Traverser.new(
34
+ recursive: true,
35
+ hidden_directories: true,
36
+ check_file: lambda do |file|
37
+ r << file.parent if file.basename.to_path == filename.to_s
38
+ end
39
+ )
40
+ ft.check_path(root_path)
41
+ r.sort
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ # Filesystem utilities.
7
+ module Fs
8
+ require_sub __FILE__
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/music/lyrics_book/resource'
5
+
6
+ module EhbrsRubyUtils
7
+ module Music
8
+ class LyricsBook
9
+ class Album < ::EhbrsRubyUtils::Music::LyricsBook::Resource
10
+ enable_simple_cache
11
+
12
+ def book
13
+ parent
14
+ end
15
+
16
+ def first_previous
17
+ previous.if_present { |v| v.songs.last }
18
+ end
19
+
20
+ def valid?
21
+ songs.any?
22
+ end
23
+
24
+ def header_title
25
+ "#{songs.first.number}-#{songs.last.number} | #{artist} | #{title}"
26
+ end
27
+
28
+ def artist
29
+ songs.lazy.map { |v| v.tag.artist }.find(&:present?)
30
+ end
31
+
32
+ def title
33
+ songs.lazy.map { |v| v.tag.album }.find(&:present?)
34
+ end
35
+
36
+ def songs_uncached
37
+ ::EhbrsRubyUtils::Music::LyricsBook::Song.create_list(self, path.children)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Music
7
+ class LyricsBook
8
+ class Resource
9
+ class << self
10
+ def create_list(parent, files)
11
+ r = files.sort.map { |path| new(parent, path) }.select(&:valid?)
12
+ previous = parent.first_previous
13
+ r.map do |e|
14
+ e.reset_cache
15
+ e.previous = previous
16
+ previous = e
17
+ end
18
+ end
19
+ end
20
+
21
+ enable_simple_cache
22
+ include ::Comparable
23
+ common_constructor :parent, :path
24
+ attr_accessor :previous
25
+
26
+ def filename
27
+ path.relative_path_from(parent.path)
28
+ end
29
+
30
+ def <=>(other)
31
+ path <=> other.path
32
+ end
33
+
34
+ def link_to_header
35
+ "<a href=\"\##{header_id}\" id=\"#{index_id}\">#{header_title}</a>"
36
+ end
37
+
38
+ def index_id
39
+ "index_#{header_id}"
40
+ end
41
+
42
+ def header_id
43
+ header_title.variableize
44
+ end
45
+
46
+ def header_index
47
+ parent.header_index + 1
48
+ end
49
+
50
+ def output_main
51
+ ::EhbrsRubyUtils::Music::LyricsBook::Resource.erb_template('main.html.erb', binding)
52
+ end
53
+
54
+ def output_index
55
+ erb_template('index.html.erb')
56
+ end
57
+
58
+ def type
59
+ self.class.name.demodulize.underscore
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/music/lyrics_book/resource'
5
+
6
+ module EhbrsRubyUtils
7
+ module Music
8
+ class LyricsBook
9
+ class Song < ::EhbrsRubyUtils::Music::LyricsBook::Resource
10
+ enable_simple_cache
11
+ delegate :book, to: :album
12
+ delegate :provider, to: :book
13
+ delegate :tag, :to_s, to: :container
14
+
15
+ def album
16
+ parent
17
+ end
18
+
19
+ def lyrics
20
+ fetch_lyrics unless lyrics_cached?
21
+ cached_lyrics
22
+ end
23
+
24
+ def valid?
25
+ tag.present?
26
+ end
27
+
28
+ def lyrics_cached?
29
+ lyrics_cache.cached?
30
+ end
31
+
32
+ def cached_lyrics
33
+ ::YAML.load_file(lyrics_cache.content_path)
34
+ end
35
+
36
+ def header_title
37
+ "#{number} - #{title}"
38
+ end
39
+
40
+ delegate :title, to: :tag
41
+
42
+ private
43
+
44
+ def container_uncached
45
+ ::EhbrsRubyUtils::Videos::Container.new(path)
46
+ end
47
+
48
+ def fetch_lyrics
49
+ lyrics = fetched_lyrics
50
+ lyrics_cache.write(lyrics.to_yaml)
51
+ end
52
+
53
+ def fetched_lyrics
54
+ container.lyrics_by_provider(provider)
55
+ end
56
+
57
+ def lyrics_cache
58
+ (%w[artist album title].map { |k| tag.send(k) } + [provider.identifier])
59
+ .inject(fs_cache) { |a, e| a.child(e) }
60
+ end
61
+
62
+ def number_uncached
63
+ previous.if_present(0, &:number) + 1
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Music
7
+ class LyricsBook
8
+ require_sub __FILE__
9
+
10
+ DEFAULT_PROVIDER_NAME = 'lyrics.com'
11
+ DEFAULT_TITLE = 'Letras de músicas'
12
+
13
+ enable_listable
14
+ lists.add_symbol :option, :provider_name, :title
15
+ enable_simple_cache
16
+ common_constructor :source_dir, :options, default: [{}] do
17
+ self.source_dir = source_dir.to_pathname
18
+ self.options = self.class.lists.option.hash_keys_validate!(options)
19
+ end
20
+
21
+ def first_previous
22
+ nil
23
+ end
24
+
25
+ def header_index
26
+ 1
27
+ end
28
+
29
+ def output
30
+ erb_template('main.html.erb')
31
+ end
32
+
33
+ def path
34
+ source_dir
35
+ end
36
+
37
+ def title
38
+ options[OPTION_TITLE].if_present(DEFAULT_TITLE)
39
+ end
40
+
41
+ private
42
+
43
+ def albums_directories_uncached
44
+ r = []
45
+ t = ::EacFs::Traverser.new
46
+ t.recursive = true
47
+ t.check_directory = ->(directory) { r << directory }
48
+ t.check_path(source_dir)
49
+ r
50
+ end
51
+
52
+ def albums_uncached
53
+ ::EhbrsRubyUtils::Music::LyricsBook::Album.create_list(self, albums_directories)
54
+ end
55
+
56
+ def provider_uncached
57
+ ::UltimateLyrics::Provider.by_name(provider_name)
58
+ end
59
+
60
+ def provider_name
61
+ options[OPTION_PROVIDER_NAME].if_present(DEFAULT_PROVIDER_NAME)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub __FILE__
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub __FILE__
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.10.0'
4
+ VERSION = '0.12.2'
5
5
  end
@@ -0,0 +1,3 @@
1
+ <% songs.each do |song| %>
2
+ <%= song.output_main %>
3
+ <% end %>
@@ -0,0 +1,15 @@
1
+ .album h2 {
2
+ background-color: lightgoldenrodyellow;
3
+ text-align: center;
4
+ }
5
+
6
+ .song {
7
+ margin-top: 4.0em;
8
+ }
9
+
10
+ .filename {
11
+ display: block;
12
+ font-size: small;
13
+ text-align: right;
14
+ font-style: italic;
15
+ }
@@ -0,0 +1,14 @@
1
+ <div class="index" >
2
+ <ul>
3
+ <% albums.each do |album| %>
4
+ <li>
5
+ <%= album.link_to_header %>
6
+ <ul>
7
+ <% album.songs.each do |song| %>
8
+ <li><%= song.link_to_header %></li>
9
+ <% end %>
10
+ </ul>
11
+ </li>
12
+ <% end %>
13
+ </ul>
14
+ </div>
@@ -0,0 +1,24 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title><%= title %></title>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
8
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
9
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">
10
+ <style>
11
+ <%= template.child('custom_style.css').content %>
12
+ </style>
13
+ </head>
14
+ <body>
15
+ <div class="container" >
16
+ <h1><%= title %></h1>
17
+ <h2>Índice</h2>
18
+ <%= erb_template('index.html.erb') %>
19
+ <% albums.each do |album| %>
20
+ <%= album.output_main %>
21
+ <% end %>
22
+ </div>
23
+ </body>
24
+ </html>
@@ -0,0 +1,8 @@
1
+ <div class="<%= type %>">
2
+ <h<%= header_index %> id='<%= header_id %>' >
3
+ <%= header_title %>
4
+ <a href="#<%= index_id %>" ><i class="bi-arrow-up-circle-fill"></i></a>
5
+ </h<%= header_index %>>
6
+ <span class="filename"><%= filename %></span>
7
+ <%= erb_template('inner.html.erb') %>
8
+ </div>
@@ -0,0 +1,9 @@
1
+ <% if lyrics.found? %>
2
+ <p class="lyrics">
3
+ <% lyrics.text.each_line do |line| %>
4
+ <%= line.strip %><br/>
5
+ <% end %>
6
+ </p>
7
+ <% else %>
8
+ <p><em>Letra indisponível.</em></p>
9
+ <% 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.10.0
4
+ version: 0.12.2
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-09-21 00:00:00.000000000 Z
11
+ date: 2021-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -30,6 +30,40 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.8.5
33
+ - !ruby/object:Gem::Dependency
34
+ name: avm
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.3'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.3.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.3.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: eac_fs
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.5'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.5'
33
67
  - !ruby/object:Gem::Dependency
34
68
  name: eac_ruby_utils
35
69
  requirement: !ruby/object:Gem::Requirement
@@ -129,9 +163,21 @@ files:
129
163
  - ".rspec"
130
164
  - ".rubocop.yml"
131
165
  - lib/ehbrs_ruby_utils.rb
166
+ - lib/ehbrs_ruby_utils/core_ext.rb
132
167
  - lib/ehbrs_ruby_utils/executables.rb
133
168
  - lib/ehbrs_ruby_utils/finances/bb_browser/docker_image.rb
169
+ - lib/ehbrs_ruby_utils/fs.rb
170
+ - lib/ehbrs_ruby_utils/fs/compressed_package.rb
171
+ - lib/ehbrs_ruby_utils/fs/selected.rb
172
+ - lib/ehbrs_ruby_utils/fs/selected/build.rb
173
+ - lib/ehbrs_ruby_utils/fs/selected/build_file.rb
134
174
  - lib/ehbrs_ruby_utils/music.rb
175
+ - lib/ehbrs_ruby_utils/music/lyrics_book.rb
176
+ - lib/ehbrs_ruby_utils/music/lyrics_book/album.rb
177
+ - lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb
178
+ - lib/ehbrs_ruby_utils/music/lyrics_book/song.rb
179
+ - lib/ehbrs_ruby_utils/patches.rb
180
+ - lib/ehbrs_ruby_utils/patches/object.rb
135
181
  - lib/ehbrs_ruby_utils/patches/object/template.rb
136
182
  - lib/ehbrs_ruby_utils/version.rb
137
183
  - lib/ehbrs_ruby_utils/videos.rb
@@ -163,6 +209,12 @@ files:
163
209
  - template/ehbrs_ruby_utils/finances/bb_browser/docker_image/README.md
164
210
  - template/ehbrs_ruby_utils/finances/bb_browser/docker_image/context/firefox.service
165
211
  - template/ehbrs_ruby_utils/finances/bb_browser/docker_image/context/startbrowser.sh
212
+ - template/ehbrs_ruby_utils/music/lyrics_book/album/inner.html.erb
213
+ - template/ehbrs_ruby_utils/music/lyrics_book/custom_style.css
214
+ - template/ehbrs_ruby_utils/music/lyrics_book/index.html.erb
215
+ - template/ehbrs_ruby_utils/music/lyrics_book/main.html.erb
216
+ - template/ehbrs_ruby_utils/music/lyrics_book/resource/main.html.erb
217
+ - template/ehbrs_ruby_utils/music/lyrics_book/song/inner.html.erb
166
218
  homepage:
167
219
  licenses: []
168
220
  metadata: {}