Class: InvoicePrinter::Document::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/invoice_printer/document/item.rb

Overview

Line items for InvoicePrinter::Document

Example:

item = InvoicePrinter::Document::Item.new(
  name: 'UX consultation',
  quantity: '4',
  unit: 'hours',
  price: '$ 25',
  tax: '$ 5'
  amount: '$ 120'
)

amount should equal the quantity times price, but this is not enforced.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, quantity: nil, unit: nil, price: nil, tax: nil, tax2: nil, tax3: nil, amount: nil) ⇒ Item

Returns a new instance of Item.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/invoice_printer/document/item.rb', line 30

def initialize(name: nil,
               quantity: nil,
               unit: nil,
               price: nil,
               tax: nil,
               tax2: nil,
               tax3: nil,
               amount: nil)
  @name = String(name)
  @quantity = String(quantity)
  @unit = String(unit)
  @price = String(price)
  @tax = String(tax)
  @tax2 = String(tax2)
  @tax3 = String(tax3)
  @amount = String(amount)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



21
22
23
# File 'lib/invoice_printer/document/item.rb', line 21

def amount
  @amount
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/invoice_printer/document/item.rb', line 21

def name
  @name
end

#priceObject (readonly)

Returns the value of attribute price.



21
22
23
# File 'lib/invoice_printer/document/item.rb', line 21

def price
  @price
end

#quantityObject (readonly)

Returns the value of attribute quantity.



21
22
23
# File 'lib/invoice_printer/document/item.rb', line 21

def quantity
  @quantity
end

#taxObject (readonly)

Returns the value of attribute tax.



21
22
23
# File 'lib/invoice_printer/document/item.rb', line 21

def tax
  @tax
end

#tax2Object (readonly)

Returns the value of attribute tax2.



21
22
23
# File 'lib/invoice_printer/document/item.rb', line 21

def tax2
  @tax2
end

#tax3Object (readonly)

Returns the value of attribute tax3.



21
22
23
# File 'lib/invoice_printer/document/item.rb', line 21

def tax3
  @tax3
end

#unitObject (readonly)

Returns the value of attribute unit.



21
22
23
# File 'lib/invoice_printer/document/item.rb', line 21

def unit
  @unit
end

Instance Method Details

#to_hObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/invoice_printer/document/item.rb', line 48

def to_h
  {
    'name': @name,
    'quantity': @quantity,
    'unit': @unit,
    'price': @price,
    'tax': @tax,
    'tax2': @tax2,
    'tax3': @tax3,
    'amount': @amount,
  }
end

#to_jsonObject



61
62
63
# File 'lib/invoice_printer/document/item.rb', line 61

def to_json
  to_h.to_json
end