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',
  breakdown: "Monday 3h\nTuesday 1h"
  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, breakdown: nil, variable: nil, quantity: nil, unit: nil, price: nil, tax: nil, tax2: nil, tax3: nil, amount: nil) ⇒ Item

Returns a new instance of Item.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/invoice_printer/document/item.rb', line 49

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

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



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

def amount
  @amount
end

#breakdownObject (readonly)

Returns the value of attribute breakdown.



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

def breakdown
  @breakdown
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

#variableObject (readonly)

Returns the value of attribute variable.



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

def variable
  @variable
end

Class Method Details

.from_json(json) ⇒ Object



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

def from_json(json)
  new(
    name: json['name'],
    breakdown: json['breakdown'],
    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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/invoice_printer/document/item.rb', line 72

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

#to_jsonObject



87
88
89
# File 'lib/invoice_printer/document/item.rb', line 87

def to_json
  to_h.to_json
end