Class: InvoicePDF::LineItem

Inherits:
Object
  • Object
show all
Defined in:
lib/invoice/line_item.rb

Overview

Line items for InvoicePDF::Invoice

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ LineItem

Creates a new LineItem to be added to the InvoicePDF::Invoice instance

Options

  • :sku - SKU of the item. (default is nil)

  • :description - Description of the item. (default is nil)

  • :price - Price of each item. (default is 0.00)

  • :quantity - Number of items. (default is 1)

  • :taxable - Is the item taxable? true/false. (default is false)

Example

item = InvoicePDF::InvoiceItem.new(:description => "Test line item", :price => 495.00, :quantity => 5)


17
18
19
20
# File 'lib/invoice/line_item.rb', line 17

def initialize(options = {})
  options = { :sku => nil, :description => nil, :quantity => 1, :price => 0.00, :taxable => false }.merge(options)
  options.each { |k, v| send("#{k}=", v) }
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/invoice/line_item.rb', line 4

def description
  @description
end

#priceObject

Returns the value of attribute price.



4
5
6
# File 'lib/invoice/line_item.rb', line 4

def price
  @price
end

#quantityObject

Returns the value of attribute quantity.



4
5
6
# File 'lib/invoice/line_item.rb', line 4

def quantity
  @quantity
end

#skuObject

Returns the value of attribute sku.



4
5
6
# File 'lib/invoice/line_item.rb', line 4

def sku
  @sku
end

#taxableObject

Returns the value of attribute taxable.



4
5
6
# File 'lib/invoice/line_item.rb', line 4

def taxable
  @taxable
end

Instance Method Details

#taxable?Boolean

Asks if the item is taxable

item = InvoicePDF::InvoiceItem.new(:description => "Test line item", :price => 495.00, :quantity => 5)
item.taxable? # => false

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/invoice/line_item.rb', line 25

def taxable?
  return false if taxable.nil? || taxable == false
  true
end

#totalObject

Return the total amount of the LineItem

item = InvoicePDF::InvoiceItem.new(:description => "Test line item", :price => 495.00, :quantity => 5)
item.total # => 2475


33
34
35
# File 'lib/invoice/line_item.rb', line 33

def total
  price * quantity
end