Class: InvoicePDF::LineItem
- Inherits:
-
Object
- Object
- InvoicePDF::LineItem
- Defined in:
- lib/invoice/line_item.rb
Overview
Line items for InvoicePDF::Invoice
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#price ⇒ Object
Returns the value of attribute price.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#sku ⇒ Object
Returns the value of attribute sku.
-
#taxable ⇒ Object
Returns the value of attribute taxable.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ LineItem
constructor
Creates a new
LineItem
to be added to the InvoicePDF::Invoice instance. -
#taxable? ⇒ Boolean
Asks if the item is taxable item = InvoicePDF::InvoiceItem.new(:description => “Test line item”, :price => 495.00, :quantity => 5) item.taxable? # => false.
-
#total ⇒ Object
Return the total amount of the
LineItem
item = InvoicePDF::InvoiceItem.new(:description => “Test line item”, :price => 495.00, :quantity => 5) item.total # => 2475.
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( = {}) = { :sku => nil, :description => nil, :quantity => 1, :price => 0.00, :taxable => false }.merge() .each { |k, v| send("#{k}=", v) } end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/invoice/line_item.rb', line 4 def description @description end |
#price ⇒ Object
Returns the value of attribute price.
4 5 6 |
# File 'lib/invoice/line_item.rb', line 4 def price @price end |
#quantity ⇒ Object
Returns the value of attribute quantity.
4 5 6 |
# File 'lib/invoice/line_item.rb', line 4 def quantity @quantity end |
#sku ⇒ Object
Returns the value of attribute sku.
4 5 6 |
# File 'lib/invoice/line_item.rb', line 4 def sku @sku end |
#taxable ⇒ Object
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
25 26 27 28 |
# File 'lib/invoice/line_item.rb', line 25 def taxable? return false if taxable.nil? || taxable == false true end |
#total ⇒ Object
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 |