class Receipts::Receipt

Attributes

attributes[R]
company[R]
custom_font[R]
id[R]
line_items[R]
message[R]
product[R]
subheading[R]

Public Class Methods

new(attributes) click to toggle source
Calls superclass method
# File lib/receipts/receipt.rb, line 5
def initialize(attributes)
  @attributes = attributes
  @id = attributes.fetch(:id)
  @company = attributes.fetch(:company)
  @line_items = attributes.fetch(:line_items)
  @custom_font = attributes.fetch(:font, {})
  @message = attributes.fetch(:message) { default_message }
  @subheading = attributes.fetch(:subheading) { default_subheading }

  super(page_size: "LETTER")

  setup_fonts if custom_font.any?
  generate
end

Private Instance Methods

charge_details() click to toggle source
# File lib/receipts/receipt.rb, line 51
def charge_details
  move_down 30
  font_size 9

  borders = line_items.length - 2

  table(line_items, width: bounds.width, cell_style: {border_color: "cccccc", inline_format: true}) do
    cells.padding = 10
    cells.borders = []
    row(0..borders).borders = [:bottom]
  end
end
default_message() click to toggle source
# File lib/receipts/receipt.rb, line 22
def default_message
  "We've received your payment for #{attributes.fetch(:product)}. You can keep this receipt for your records. For questions, contact us anytime at <color rgb='326d92'><link href='mailto:#{company.fetch(:email)}?subject=Charge ##{id}'><b>#{company.fetch(:email)}</b></link></color>."
end
default_subheading() click to toggle source
# File lib/receipts/receipt.rb, line 26
def default_subheading
  "RECEIPT FOR CHARGE #%{id}"
end
description() click to toggle source
# File lib/receipts/receipt.rb, line 43
def description
  move_down 8
  text "<color rgb='a6a6a6'>#{subheading % {id: id}}</color>", inline_format: true

  move_down 30
  text message, inline_format: true, leading: 4
end
generate() click to toggle source
# File lib/receipts/receipt.rb, line 30
def generate
  header
  description
  charge_details
  footer
end
header(height: 24) click to toggle source
# File lib/receipts/receipt.rb, line 37
def header(height: 24)
  logo = company[:logo]
  return if logo.nil?
  image load_image(logo), height: height
end