Class: MusicBox::CoverMaker
- Inherits:
-
Object
- Object
- MusicBox::CoverMaker
- Defined in:
- lib/musicbox/cover_maker.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ CoverMaker
constructor
A new instance of CoverMaker.
- #make_covers(releases) ⇒ Object
- #write(output_file) ⇒ Object
Constructor Details
#initialize ⇒ CoverMaker
Returns a new instance of CoverMaker.
11 12 13 |
# File 'lib/musicbox/cover_maker.rb', line 11 def initialize @pdf = Prawn::Document.new end |
Class Method Details
.make_covers(*releases, output_file:) ⇒ Object
5 6 7 8 9 |
# File 'lib/musicbox/cover_maker.rb', line 5 def self.make_covers(*releases, output_file:) cover_maker = new cover_maker.make_covers(releases) cover_maker.write(output_file) end |
Instance Method Details
#make_covers(releases) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/musicbox/cover_maker.rb', line 15 def make_covers(releases) size = 4.75.in top = 10.in releases.each_with_index do |release, i| album = release.album unless album&.has_cover? puts "Release #{release.id} has no cover" next end @pdf.start_new_page if i > 0 @pdf.fill do @pdf.rectangle [0, top], size, size end @pdf.image album.cover_file.to_s, at: [0, top], width: size, fit: [size, size], position: :center @pdf.stroke do @pdf.rectangle [0, top], size, size end end end |
#write(output_file) ⇒ Object
43 44 45 |
# File 'lib/musicbox/cover_maker.rb', line 43 def write(output_file) @pdf.render_file(output_file.to_s) end |