songbook 0.4.0 → 0.5.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: d862405d26a445cf66da2b06ed4fb5c35bb70ad1e14633649d2f05f141d0f340
4
- data.tar.gz: d93153d5a854ff317a3be0c20608134aa4c343085eadef3be24ab794abdeb061
3
+ metadata.gz: 77a576ace791a1d2336d9a1028864b0430263bbd8ef7a7ee1fab7b3c32feead6
4
+ data.tar.gz: cc47254a55d12c987e451ca82aa76dfe4a054b9685f624821196cce1b8396ee5
5
5
  SHA512:
6
- metadata.gz: 632ccbdd9d3e895412c0501b7bffdeed7824fb708949eb9eaee7d91e107c0b43d34c9a92a83fa9780ec1eb2da857275476dedcf401c58408f967fb73a17f4398
7
- data.tar.gz: 83831f2a8e03990d1bb5fce2b3338c70f62f8764b469865df8fb0bcaac2400f0193583926defa16c1471cc46fe5cf8a4ac6cc5c246f70af46bb791c11ffe59e2
6
+ metadata.gz: 01c14ac68fe116b3119b4861b0b43fb4061df58dc7ca843f23f1cfb16f4b52560054c39a3e356f76975710a9080e4ce819a88d414d302e52ed24b1b2bc7f6e3f
7
+ data.tar.gz: 671c92a26a6f4b5c314573c156a3fcabe93ea4ea1b965947aadc4a4443ba2300fb12e16c41782d1fe724a8b0eefd6a2cc320a60fe7fb892faea45c88186f10c6
@@ -27,14 +27,11 @@ module Songbook
27
27
  end
28
28
 
29
29
  def song
30
- table_width = song_data['config']['table_width'] if song_data['config']
31
-
32
30
  @song ||= Song.new(
33
31
  title: File.basename(input_path, '.yml'),
34
32
  details: song_data['details'],
35
33
  chords: song_data['chords'],
36
- lyrics: song_data['lyrics'],
37
- table_width: table_width
34
+ lyrics: song_data['lyrics']
38
35
  )
39
36
  end
40
37
 
@@ -29,10 +29,10 @@ module Songbook
29
29
  def verses_table
30
30
  table = TTY::Table.new do |t|
31
31
  song.verses.each do |verse|
32
- t << ["[#{verse.title}]", nil]
32
+ t << [verse.formatted_title, nil]
33
33
 
34
34
  verse.lines.each do |line|
35
- t << [line.lyrics, line.chords]
35
+ t << [line.chords, line.lyrics]
36
36
  end
37
37
 
38
38
  t << SEPARATOR
@@ -48,22 +48,22 @@ module Songbook
48
48
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
49
49
 
50
50
  def table_settings
51
- { column_widths: [lyrics_column_width, nil], multiline: true }
51
+ { resize: true, width: table_width }
52
52
  end
53
53
 
54
- def lyrics_column_width
55
- [
56
- song.table_width - chords_column_width - LYRICS_CHORDS_SEPARATOR.length,
57
- max_lyrics_column_width
58
- ].min
54
+ def table_width
55
+ chords_column_width + LYRICS_CHORDS_SEPARATOR.length + lyrics_column_width
59
56
  end
60
57
 
61
- def max_lyrics_column_width
58
+ def lyrics_column_width
62
59
  song.verses.flat_map(&:lines).flat_map(&:lyrics).map(&:length).max
63
60
  end
64
61
 
65
62
  def chords_column_width
66
- song.verses.flat_map(&:lines).flat_map(&:chords).map(&:length).max
63
+ chord_column_texts =
64
+ song.verses.flat_map(&:lines).flat_map(&:chords) + song.verses.map(&:formatted_title)
65
+
66
+ chord_column_texts.map(&:length).max
67
67
  end
68
68
  end
69
69
  end
data/lib/songbook/song.rb CHANGED
@@ -4,16 +4,13 @@ require_relative 'verse'
4
4
 
5
5
  module Songbook
6
6
  class Song
7
- TABLE_WIDTH = 80
7
+ attr_reader :title, :details, :chords, :lyrics
8
8
 
9
- attr_reader :title, :details, :chords, :lyrics, :table_width
10
-
11
- def initialize(title:, details:, chords:, lyrics:, table_width: nil)
9
+ def initialize(title:, details:, chords:, lyrics:)
12
10
  @title = title
13
11
  @details = details
14
12
  @chords = chords
15
13
  @lyrics = lyrics
16
- @table_width = table_width || TABLE_WIDTH
17
14
  end
18
15
 
19
16
  def verses
@@ -27,6 +27,10 @@ module Songbook
27
27
  end
28
28
  # rubocop:enable Metrics/AbcSize
29
29
 
30
+ def formatted_title
31
+ "[#{title}]"
32
+ end
33
+
30
34
  private
31
35
 
32
36
  def lyric_lines
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Songbook
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: songbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Mendoza
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-28 00:00:00.000000000 Z
11
+ date: 2023-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-table
@@ -135,7 +135,7 @@ licenses:
135
135
  - MIT
136
136
  metadata:
137
137
  allowed_push_host: https://rubygems.org
138
- post_install_message:
138
+ post_install_message:
139
139
  rdoc_options: []
140
140
  require_paths:
141
141
  - lib
@@ -150,8 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.1.6
154
- signing_key:
153
+ rubygems_version: 3.3.22
154
+ signing_key:
155
155
  specification_version: 4
156
156
  summary: Songbook
157
157
  test_files: []