class MusicBox::CoverMaker

Public Class Methods

make_covers(*releases, output_file:) click to toggle source
# 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
new() click to toggle source
# File lib/musicbox/cover_maker.rb, line 11
def initialize
  @pdf = Prawn::Document.new
end

Public Instance Methods

make_covers(releases) click to toggle source
# 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) click to toggle source
# File lib/musicbox/cover_maker.rb, line 43
def write(output_file)
  @pdf.render_file(output_file.to_s)
end