class MusicBox::LabelMaker

Public Class Methods

make_labels(*labels, output_file:) click to toggle source
# File lib/musicbox/label_maker.rb, line 5
def self.make_labels(*labels, output_file:)
  label_maker = new
  label_maker.make_labels(labels)
  label_maker.write(output_file)
end
new() click to toggle source
# File lib/musicbox/label_maker.rb, line 11
def initialize
  @font_dir = Path.new('~/Fonts/D/DejaVu Sans')
  @pdf = Prawn::Document.new(page_size: [3.5.in, 1.14.in], margin: 0)
  @pdf.font_families.update(font_families)
  @pdf.font('DejaVuSans')
  @pdf.font_size(12)
end

Public Instance Methods

font_families() click to toggle source
# File lib/musicbox/label_maker.rb, line 46
def font_families
  {
    'DejaVuSans' => {
      normal: 'DejaVuSans',
      italic: 'DejaVuSans-Oblique',
      bold: 'DejaVuSans-Bold',
      bold_italic: 'DejaVuSans-BoldOblique',
    }.map { |style, file|
      [style, (@font_dir / file).add_extension('.ttf').realpath.to_s ]
    }.to_h
  }
end
make_labels(labels) click to toggle source
# File lib/musicbox/label_maker.rb, line 19
    def make_labels(labels)
      labels.sort_by { |l| l.values_at(:key, :year) }.each_with_index do |label, i|
        @pdf.start_new_page if i > 0
        @pdf.bounding_box([0, 1.in], width: 2.5.in, height: 1.in) do
          # ;;@pdf.transparent(0.5) { @pdf.stroke_bounds }
          @pdf.text_box <<~END, inline_format: true
            <b>#{label[:artist]}</b>
            <i>#{label[:title]}</i>
          END
        end
        @pdf.bounding_box([2.7.in, 1.in], width: 0.8.in, height: 1.in) do
          # ;;@pdf.transparent(0.5) { @pdf.stroke_bounds }
          @pdf.text_box <<~END, align: :right, inline_format: true
            <b>#{label[:key]}
            #{label[:year]}</b>

            #{label[:format]}
            #{label[:id]}
          END
        end
      end
    end
write(output_file) click to toggle source
# File lib/musicbox/label_maker.rb, line 42
def write(output_file)
  @pdf.render_file(output_file.to_s)
end