Class: InvoicePrinter::Document::Item
- Inherits:
-
Object
- Object
- InvoicePrinter::Document::Item
- 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
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#tax ⇒ Object
readonly
Returns the value of attribute tax.
-
#tax2 ⇒ Object
readonly
Returns the value of attribute tax2.
-
#tax3 ⇒ Object
readonly
Returns the value of attribute tax3.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#variable ⇒ Object
readonly
Returns the value of attribute variable.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name: nil, variable: nil, quantity: nil, unit: nil, price: nil, tax: nil, tax2: nil, tax3: nil, amount: nil) ⇒ Item
constructor
A new instance of Item.
- #to_h ⇒ Object
- #to_json ⇒ Object
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
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
20 21 22 |
# File 'lib/invoice_printer/document/item.rb', line 20 def amount @amount end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/invoice_printer/document/item.rb', line 20 def name @name end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
20 21 22 |
# File 'lib/invoice_printer/document/item.rb', line 20 def price @price end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
20 21 22 |
# File 'lib/invoice_printer/document/item.rb', line 20 def quantity @quantity end |
#tax ⇒ Object (readonly)
Returns the value of attribute tax.
20 21 22 |
# File 'lib/invoice_printer/document/item.rb', line 20 def tax @tax end |
#tax2 ⇒ Object (readonly)
Returns the value of attribute tax2.
20 21 22 |
# File 'lib/invoice_printer/document/item.rb', line 20 def tax2 @tax2 end |
#tax3 ⇒ Object (readonly)
Returns the value of attribute tax3.
20 21 22 |
# File 'lib/invoice_printer/document/item.rb', line 20 def tax3 @tax3 end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
20 21 22 |
# File 'lib/invoice_printer/document/item.rb', line 20 def unit @unit end |
#variable ⇒ Object (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_h ⇒ Object
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_json ⇒ Object
81 82 83 |
# File 'lib/invoice_printer/document/item.rb', line 81 def to_json to_h.to_json end |