songbook 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.overcommit.yml +31 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/rspec +32 -0
- data/bin/setup +8 -0
- data/exe/songbook +27 -0
- data/lib/songbook.rb +22 -0
- data/lib/songbook/generate_song_file.rb +42 -0
- data/lib/songbook/generate_song_files.rb +31 -0
- data/lib/songbook/render_song.rb +70 -0
- data/lib/songbook/song.rb +59 -0
- data/lib/songbook/verse.rb +40 -0
- data/lib/songbook/version.rb +5 -0
- data/songbook.gemspec +43 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 90cddbc8c8b4aa8edfc5059faf10479cdab00951f5ac602402a7825d7de218b0
|
4
|
+
data.tar.gz: 61f2a951e620756d1b443f7f228e35aac862b1f28cb06d224aae9a9fce955bba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63300706dc45b01e44dd4e07a40d6641523e05faecc5487851a30d0d7d6fedb3325f92449ff3e1c021cb99bd91e2cf01a97ae7e032494961007865b3c12f414a
|
7
|
+
data.tar.gz: 5f49d78bfb8e6d946df5ce314806a3a0ae1484a2756892a08422ce8c197e7a4ba91af98970fb3a2a2458fc08f8f31a471ea0ea901304b874cc73cbcd381adef8
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Use this file to configure the Overcommit hooks you wish to use. This will
|
2
|
+
# extend the default configuration defined in:
|
3
|
+
# https://github.com/brigade/overcommit/blob/master/config/default.yml
|
4
|
+
#
|
5
|
+
# At the topmost level of this YAML file is a key representing type of hook
|
6
|
+
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
|
7
|
+
# customize each hook, such as whether to only run it on certain files (via
|
8
|
+
# `include`), whether to only display output if it fails (via `quiet`), etc.
|
9
|
+
#
|
10
|
+
# For a complete list of hooks, see:
|
11
|
+
# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
|
12
|
+
#
|
13
|
+
# For a complete list of options that you can use to customize hooks, see:
|
14
|
+
# https://github.com/brigade/overcommit#configuration
|
15
|
+
#
|
16
|
+
# Uncomment the following lines to make the configuration take effect.
|
17
|
+
|
18
|
+
PreCommit:
|
19
|
+
RuboCop:
|
20
|
+
enabled: true
|
21
|
+
on_warn: fail # Treat all warnings as failures
|
22
|
+
|
23
|
+
TrailingWhitespace:
|
24
|
+
enabled: true
|
25
|
+
|
26
|
+
#PostCheckout:
|
27
|
+
# ALL: # Special hook name that customizes all hooks of this type
|
28
|
+
# quiet: true # Change all post-checkout hooks to only display output on failure
|
29
|
+
#
|
30
|
+
# IndexTags:
|
31
|
+
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at gsmendoza@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 George Mendoza
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Songbook
|
2
|
+
|
3
|
+
Songbook is an application I use to generate chord tablatures i.e. tabs that include only chords and lyrics.
|
4
|
+
|
5
|
+
Unlike traditional tabs, the tabs that the app generates have their chords placed to the right of the lyrics. This makes it easy to see the chord progressions of a song.
|
6
|
+
|
7
|
+
For samples of the YAML song templates and the tabs that were generated from them, please see https://github.com/gsmendoza/songs.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'songbook'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install songbook
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
* `songbook bob-marley-three-little-birds.yml bob-marley-three-little-birds.txt`
|
28
|
+
* `songbook . /tmp/songbook` - Generate tabs for all of the YAML files in the present directory and save them in `/tmp/songbook`. Creates `/tmp/songbook` if it does not exist.
|
29
|
+
* `songbook /home/bob-marley-three-little-birds.yml` - Same as `/home/songbook bob-marley-three-little-birds.yml /home/bob-marley-three-little-birds.txt`
|
30
|
+
* `songbook` - Same as `songbook . .`
|
31
|
+
|
32
|
+
**WARNING:** I haven't made any attempt to make a proper implementation of the app's CLI. If for some reason, you decide to become the _second_ user of this app, and the CLI annoys you, let me know :)
|
33
|
+
|
34
|
+
## Development
|
35
|
+
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
|
+
|
38
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/songbook. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
47
|
+
|
48
|
+
## Code of Conduct
|
49
|
+
|
50
|
+
Everyone interacting in the Songbook project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/songbook/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'songbook'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/rspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'pathname'
|
12
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 150))
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort(
|
22
|
+
"Your `bin/bundle` was not generated by Bundler, so this binstub cannot
|
23
|
+
run. Replace `bin/bundle` by running `bundle binstubs bundler --force`,
|
24
|
+
then run this command again."
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'rubygems'
|
30
|
+
require 'bundler/setup'
|
31
|
+
|
32
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/bin/setup
ADDED
data/exe/songbook
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'pathname'
|
5
|
+
require 'songbook'
|
6
|
+
require 'songbook/generate_song_files'
|
7
|
+
|
8
|
+
input_path = Songbook.select_input_path(ARGV.first)
|
9
|
+
output_path = Songbook.select_output_path(input_path: input_path, output_path: ARGV.drop(1).last)
|
10
|
+
|
11
|
+
input_pathname = Pathname.new(input_path)
|
12
|
+
output_pathname = Pathname.new(output_path)
|
13
|
+
|
14
|
+
service =
|
15
|
+
if input_pathname.file?
|
16
|
+
Songbook::GenerateSongFile.new(
|
17
|
+
input_path: input_path, output_path: output_path, verbose: true
|
18
|
+
)
|
19
|
+
else
|
20
|
+
output_pathname.mkpath
|
21
|
+
|
22
|
+
Songbook::GenerateSongFiles.new(
|
23
|
+
input_path: input_path, output_path: output_path, verbose: true
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
service.call
|
data/lib/songbook.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'songbook/version'
|
5
|
+
|
6
|
+
module Songbook
|
7
|
+
def self.select_input_path(path)
|
8
|
+
path || '.'
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.select_output_path(input_path:, output_path:)
|
12
|
+
if output_path
|
13
|
+
output_path
|
14
|
+
elsif !Pathname.new(input_path).exist?
|
15
|
+
raise "Cannot find input_path '#{input_path}'"
|
16
|
+
elsif Pathname.new(input_path).file?
|
17
|
+
input_path.sub(/\.ya?ml$/, '.txt')
|
18
|
+
else
|
19
|
+
input_path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require_relative 'song'
|
5
|
+
require_relative 'render_song'
|
6
|
+
|
7
|
+
module Songbook
|
8
|
+
class GenerateSongFile
|
9
|
+
attr_reader :input_path, :output_path, :verbose
|
10
|
+
|
11
|
+
def initialize(input_path:, output_path:, verbose: false)
|
12
|
+
@input_path = input_path
|
13
|
+
@output_path = output_path
|
14
|
+
@verbose = verbose
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
puts "Generating #{output_path}..." if verbose
|
19
|
+
|
20
|
+
File.open(output_path, 'w') { |file| file.write(song_text) }
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def song_text
|
26
|
+
@song_text ||= RenderSong.new(song).call
|
27
|
+
end
|
28
|
+
|
29
|
+
def song
|
30
|
+
@song ||= Song.new(
|
31
|
+
title: File.basename(input_path, '.yml'),
|
32
|
+
details: song_data['details'],
|
33
|
+
chords: song_data['chords'],
|
34
|
+
lyrics: song_data['lyrics']
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def song_data
|
39
|
+
@song_data ||= YAML.load_file(input_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'generate_song_file'
|
4
|
+
|
5
|
+
module Songbook
|
6
|
+
class GenerateSongFiles
|
7
|
+
attr_reader :input_path, :output_path, :verbose
|
8
|
+
|
9
|
+
def initialize(input_path:, output_path:, verbose: false)
|
10
|
+
@input_path = input_path
|
11
|
+
@output_path = output_path
|
12
|
+
@verbose = verbose
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
Dir.glob("#{input_path}/*.yml") do |filename|
|
17
|
+
basename = File.basename(filename, '.yml')
|
18
|
+
|
19
|
+
output_file = "#{output_path}/#{basename}.txt"
|
20
|
+
|
21
|
+
service = GenerateSongFile.new(
|
22
|
+
input_path: filename,
|
23
|
+
output_path: output_file,
|
24
|
+
verbose: verbose
|
25
|
+
)
|
26
|
+
|
27
|
+
service.call
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tty-table'
|
4
|
+
|
5
|
+
module Songbook
|
6
|
+
class RenderSong
|
7
|
+
SEPARATOR = [nil, nil].freeze
|
8
|
+
TABLE_WIDTH = 80
|
9
|
+
LYRICS_CHORDS_SEPARATOR = ' '
|
10
|
+
|
11
|
+
attr_reader :song
|
12
|
+
|
13
|
+
def initialize(song)
|
14
|
+
@song = song
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
result = <<~RESULT
|
19
|
+
#{song.title}\n
|
20
|
+
#{song.details}
|
21
|
+
#{verses_table}
|
22
|
+
RESULT
|
23
|
+
|
24
|
+
result.split("\n").map(&:rstrip).join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
30
|
+
def verses_table
|
31
|
+
table = TTY::Table.new do |t|
|
32
|
+
song.verses.each do |verse|
|
33
|
+
t << ["[#{verse.title}]", nil]
|
34
|
+
|
35
|
+
verse.lines.each do |line|
|
36
|
+
t << [line.lyrics, line.chords]
|
37
|
+
end
|
38
|
+
|
39
|
+
t << SEPARATOR
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
table.render(:basic, table_settings) do |renderer|
|
44
|
+
renderer.border do
|
45
|
+
center LYRICS_CHORDS_SEPARATOR
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
50
|
+
|
51
|
+
def table_settings
|
52
|
+
{ column_widths: [lyrics_column_width, nil], multiline: true }
|
53
|
+
end
|
54
|
+
|
55
|
+
def lyrics_column_width
|
56
|
+
[
|
57
|
+
TABLE_WIDTH - chords_column_width - LYRICS_CHORDS_SEPARATOR.length,
|
58
|
+
max_lyrics_column_width
|
59
|
+
].min
|
60
|
+
end
|
61
|
+
|
62
|
+
def max_lyrics_column_width
|
63
|
+
song.verses.flat_map(&:lines).flat_map(&:lyrics).map(&:length).max
|
64
|
+
end
|
65
|
+
|
66
|
+
def chords_column_width
|
67
|
+
song.verses.flat_map(&:lines).flat_map(&:chords).map(&:length).max
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'verse'
|
4
|
+
|
5
|
+
module Songbook
|
6
|
+
class Song
|
7
|
+
attr_reader :title, :details, :chords, :lyrics
|
8
|
+
|
9
|
+
def initialize(title:, details:, chords:, lyrics:)
|
10
|
+
@title = title
|
11
|
+
@details = details
|
12
|
+
@chords = chords
|
13
|
+
@lyrics = lyrics
|
14
|
+
end
|
15
|
+
|
16
|
+
def verses
|
17
|
+
lyrics.map do |lyrics_verse|
|
18
|
+
verse_title = find_verse_title(lyrics_verse)
|
19
|
+
verse_lyrics = find_verse_lyrics(lyrics_verse)
|
20
|
+
|
21
|
+
Verse.new(
|
22
|
+
title: verse_title,
|
23
|
+
lyrics: verse_lyrics,
|
24
|
+
chords: chords[verse_title]
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def find_verse_title(lyrics_verse)
|
32
|
+
if lyrics_verse.is_a?(String)
|
33
|
+
lyrics_verse
|
34
|
+
elsif lyrics_verse.is_a?(Hash)
|
35
|
+
lyrics_verse.keys.first
|
36
|
+
else
|
37
|
+
raise "Unknown lyrics_verse type: #{lyrics_verse.class}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def find_verse_lyrics(lyrics_verse)
|
42
|
+
if lyrics_verse.is_a?(String)
|
43
|
+
find_matching_lyrics_verse(lyrics_verse).values.first
|
44
|
+
elsif lyrics_verse.is_a?(Hash)
|
45
|
+
lyrics_verse.values.first
|
46
|
+
else
|
47
|
+
raise "Unknown lyrics_verse type: #{lyrics_verse.class}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_matching_lyrics_verse(verse_title)
|
52
|
+
lyrics
|
53
|
+
.select { |lyrics_verse_i| lyrics_verse_i.is_a?(Hash) }
|
54
|
+
.find do |lyrics_verse_i|
|
55
|
+
lyrics_verse_i.keys.first == verse_title
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Songbook
|
6
|
+
class Verse
|
7
|
+
attr_reader :title, :chords, :lyrics
|
8
|
+
|
9
|
+
def initialize(title:, chords:, lyrics:)
|
10
|
+
raise "Verse '#{title} chords is nil" if chords.nil?
|
11
|
+
|
12
|
+
@title = title
|
13
|
+
@chords = chords
|
14
|
+
@lyrics = lyrics
|
15
|
+
end
|
16
|
+
|
17
|
+
# rubocop:disable Metrics/AbcSize
|
18
|
+
def lines
|
19
|
+
if lyric_lines.length != chord_lines.length
|
20
|
+
raise "'#{title}' lyrics length doesn't match chords length:\n\n" \
|
21
|
+
"#{lyric_lines}\n\nversus\n\n#{chord_lines}"
|
22
|
+
end
|
23
|
+
|
24
|
+
lyric_lines.map.with_index do |lyric_line, i|
|
25
|
+
OpenStruct.new(lyrics: lyric_line, chords: chord_lines[i])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
# rubocop:enable Metrics/AbcSize
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def lyric_lines
|
33
|
+
@lyric_lines ||= lyrics.split("\n")
|
34
|
+
end
|
35
|
+
|
36
|
+
def chord_lines
|
37
|
+
@chord_lines ||= chords.split("\n")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/songbook.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'songbook/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'songbook'
|
9
|
+
spec.version = Songbook::VERSION
|
10
|
+
spec.authors = ['George Mendoza']
|
11
|
+
spec.email = ['gsmendoza@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Songbook'
|
14
|
+
spec.description = 'Generate a songbook from YAML files'
|
15
|
+
spec.homepage = 'https://github.com/gsmendoza/songbook'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the
|
19
|
+
# 'allowed_push_host' to allow pushing to a single host or delete this section
|
20
|
+
# to allow pushing to any host.
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
23
|
+
else
|
24
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
25
|
+
'public gem pushes.'
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
29
|
+
f.match(%r{^(test|spec|features)/})
|
30
|
+
end
|
31
|
+
spec.bindir = 'exe'
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ['lib']
|
34
|
+
|
35
|
+
spec.add_dependency 'tty-table', '~> 0.10'
|
36
|
+
|
37
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
38
|
+
spec.add_development_dependency 'byebug'
|
39
|
+
spec.add_development_dependency 'overcommit', '~> 0.45'
|
40
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
41
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
42
|
+
spec.add_development_dependency 'rubocop', '~> 0.55'
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: songbook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- George Mendoza
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tty-table
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: overcommit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.45'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.45'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.55'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.55'
|
111
|
+
description: Generate a songbook from YAML files
|
112
|
+
email:
|
113
|
+
- gsmendoza@gmail.com
|
114
|
+
executables:
|
115
|
+
- songbook
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".overcommit.yml"
|
121
|
+
- ".rspec"
|
122
|
+
- ".rubocop.yml"
|
123
|
+
- ".travis.yml"
|
124
|
+
- CODE_OF_CONDUCT.md
|
125
|
+
- Gemfile
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/rspec
|
131
|
+
- bin/setup
|
132
|
+
- exe/songbook
|
133
|
+
- lib/songbook.rb
|
134
|
+
- lib/songbook/generate_song_file.rb
|
135
|
+
- lib/songbook/generate_song_files.rb
|
136
|
+
- lib/songbook/render_song.rb
|
137
|
+
- lib/songbook/song.rb
|
138
|
+
- lib/songbook/verse.rb
|
139
|
+
- lib/songbook/version.rb
|
140
|
+
- songbook.gemspec
|
141
|
+
homepage: https://github.com/gsmendoza/songbook
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
metadata:
|
145
|
+
allowed_push_host: https://rubygems.org
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.7.7
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: Songbook
|
166
|
+
test_files: []
|