ehbrs_ruby_utils 0.11.0 → 0.12.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: 230878af735547a11e32b70f8c142dcc5adb581ea9b00ced816b7944b16ca532
4
- data.tar.gz: e28ef687a67b61e17066721e725cfdb6fe8daa62f886e513f1750f4a013a4835
3
+ metadata.gz: 06d0a1af5ebc96661f619963ffda32539b7d15a4d84e17fe17ba148b98cb674f
4
+ data.tar.gz: 3ab5bb3db004590e52e997539c0a81937dce524c89cb9952f192a27fcbd74eeb
5
5
  SHA512:
6
- metadata.gz: 9663bc98612d1f83e1654a3f518c6319d12395528c01392049360fc2eca89c727e7c5e8d4acfec04ba8062bf6601cbebc45576203ac78adf3f15b3826c303d67
7
- data.tar.gz: '0805245a0e679bfdeeb3be0d621acd8daa5765042e697922d6e75c69f9d58c8fed91e7722ea4903cf3f97106a10b737a950f5f02210c3d6d2c2d5aff2dbba752'
6
+ metadata.gz: fd975103eb147ab5dbd728e01ebb4d42f930f353fe6efb7e3286c6048182345152866917031f65b801d5411d966e415f88819eaaab2116c51854db3ce7d61d29
7
+ data.tar.gz: 341d04b398d655aceb84181dd4f1131c0eda4e43fe5e7ea80f709344e1ac222d4190dd10a1fa782b3d2b3b9e5f1af1b90659fc839c5c743e01a3bcaa586e19bd
@@ -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'
@@ -7,7 +7,7 @@ module EhbrsRubyUtils
7
7
  module Fs
8
8
  class Selected
9
9
  class Build
10
- DEFAULT_TARGET_BASENAME_PROC = ::Proc.new { |basename| basename }
10
+ DEFAULT_TARGET_BASENAME_PROC = ::Proc.new { |path| path.basename.to_path }
11
11
 
12
12
  attr_reader :selected, :target_dir, :target_basename_proc
13
13
 
@@ -19,7 +19,7 @@ module EhbrsRubyUtils
19
19
  end
20
20
 
21
21
  def target_basename
22
- build.target_basename_proc.call(path.basename.to_path)
22
+ build.target_basename_proc.call(path)
23
23
  end
24
24
  end
25
25
  end
@@ -16,8 +16,8 @@ module EhbrsRubyUtils
16
16
  self.options = self.class.lists.option.hash_keys_validate!(options)
17
17
  end
18
18
 
19
- def build(target_dir)
20
- ::EhbrsRubyUtils::Fs::Selected::Build.new(self, target_dir)
19
+ def build(target_dir, &directory_target_basename)
20
+ ::EhbrsRubyUtils::Fs::Selected::Build.new(self, target_dir, &directory_target_basename)
21
21
  end
22
22
 
23
23
  def filename
@@ -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 = ::EacRubyUtils::Fs::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.11.0'
4
+ VERSION = '0.12.0'
5
5
  end
@@ -0,0 +1,3 @@
1
+ <% songs.each do |song| %>
2
+ <%= song.output_main %>
3
+ <% end %>
@@ -0,0 +1,11 @@
1
+ .album h2 {
2
+ background-color: lightgoldenrodyellow;
3
+ text-align: center;
4
+ }
5
+
6
+ .filename {
7
+ display: block;
8
+ font-size: small;
9
+ text-align: right;
10
+ font-style: italic;
11
+ }
@@ -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,5 @@
1
+ <% if lyrics.found? %>
2
+ <pre><%= lyrics.text %></pre>
3
+ <% else %>
4
+ <p><em>Letra indisponível.</em></p>
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.11.0
4
+ version: 0.12.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: 2021-09-22 00:00:00.000000000 Z
11
+ date: 2021-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -149,6 +149,7 @@ files:
149
149
  - ".rspec"
150
150
  - ".rubocop.yml"
151
151
  - lib/ehbrs_ruby_utils.rb
152
+ - lib/ehbrs_ruby_utils/core_ext.rb
152
153
  - lib/ehbrs_ruby_utils/executables.rb
153
154
  - lib/ehbrs_ruby_utils/finances/bb_browser/docker_image.rb
154
155
  - lib/ehbrs_ruby_utils/fs.rb
@@ -157,6 +158,12 @@ files:
157
158
  - lib/ehbrs_ruby_utils/fs/selected/build.rb
158
159
  - lib/ehbrs_ruby_utils/fs/selected/build_file.rb
159
160
  - lib/ehbrs_ruby_utils/music.rb
161
+ - lib/ehbrs_ruby_utils/music/lyrics_book.rb
162
+ - lib/ehbrs_ruby_utils/music/lyrics_book/album.rb
163
+ - lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb
164
+ - lib/ehbrs_ruby_utils/music/lyrics_book/song.rb
165
+ - lib/ehbrs_ruby_utils/patches.rb
166
+ - lib/ehbrs_ruby_utils/patches/object.rb
160
167
  - lib/ehbrs_ruby_utils/patches/object/template.rb
161
168
  - lib/ehbrs_ruby_utils/version.rb
162
169
  - lib/ehbrs_ruby_utils/videos.rb
@@ -188,6 +195,12 @@ files:
188
195
  - template/ehbrs_ruby_utils/finances/bb_browser/docker_image/README.md
189
196
  - template/ehbrs_ruby_utils/finances/bb_browser/docker_image/context/firefox.service
190
197
  - template/ehbrs_ruby_utils/finances/bb_browser/docker_image/context/startbrowser.sh
198
+ - template/ehbrs_ruby_utils/music/lyrics_book/album/inner.html.erb
199
+ - template/ehbrs_ruby_utils/music/lyrics_book/custom_style.css
200
+ - template/ehbrs_ruby_utils/music/lyrics_book/index.html.erb
201
+ - template/ehbrs_ruby_utils/music/lyrics_book/main.html.erb
202
+ - template/ehbrs_ruby_utils/music/lyrics_book/resource/main.html.erb
203
+ - template/ehbrs_ruby_utils/music/lyrics_book/song/inner.html.erb
191
204
  homepage:
192
205
  licenses: []
193
206
  metadata: {}