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',
  variable: 'June 2008',
  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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Item.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/invoice_printer/document/item.rb', line 46

def initialize(name:     nil,
               variable: nil,
               quantity: nil,
               unit:     nil,
               price:    nil,
               tax:      nil,
               tax2:     nil,
               tax3:     nil,
               amount:   nil)

  @name     = String(name)
  @variable = String(variable)
  @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.



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

def amount
  @amount
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#priceObject (readonly)

Returns the value of attribute price.



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

def price
  @price
end

#quantityObject (readonly)

Returns the value of attribute quantity.



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

def quantity
  @quantity
end

#taxObject (readonly)

Returns the value of attribute tax.



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

def tax
  @tax
end

#tax2Object (readonly)

Returns the value of attribute tax2.



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

def tax2
  @tax2
end

#tax3Object (readonly)

Returns the value of attribute tax3.



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

def tax3
  @tax3
end

#unitObject (readonly)

Returns the value of attribute unit.



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

def unit
  @unit
end

#variableObject (readonly)

Returns the value of attribute variable.



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

def variable
  @variable
end

Class Method Details

.from_json(json) ⇒ Object



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

def from_json(json)
  new(
    name:     json['name'],
    variable: json['variable'],
    quantity: json['quantity'],
    unit:     json['unit'],
    price:    json['price'],
    tax:      json['tax'],
    tax2:     json['tax2'],
    tax3:     json['tax3'],
    amount:   json['amount']
  )
end

Instance Method Details

#to_hObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/invoice_printer/document/item.rb', line 67

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

#to_jsonObject



81
82
83
# File 'lib/invoice_printer/document/item.rb', line 81

def to_json
  to_h.to_json
end