Class: Clearbooks::Item

Inherits:
Base
  • Object
show all
Defined in:
lib/clearbooks/model/item.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

build, create

Constructor Details

#initialize(data) ⇒ Item

Returns a new instance of Item.

Parameters:



50
51
52
53
54
55
56
57
# File 'lib/clearbooks/model/item.rb', line 50

def initialize data
  @description  = data.savon :description
  @unit_price   = BigDecimal.new data.savon(:unit_price), 2
  @quantity     = data.savon(:quantity).to_i
  @type         = data.savon :type
  @vat          = data.savon :vat
  @vat_rate     = data.savon :vat_rate
end

Instance Attribute Details

#descriptionString (readonly)

Required.



16
17
18
# File 'lib/clearbooks/model/item.rb', line 16

def description
  @description
end

#quantityFixnum (readonly)

Required.



26
27
28
# File 'lib/clearbooks/model/item.rb', line 26

def quantity
  @quantity
end

#typeString (readonly)

Required. The account code identifying the revenue stream.



31
32
33
# File 'lib/clearbooks/model/item.rb', line 31

def type
  @type
end

#unit_priceBigDecimal (readonly)

Required.

Returns:

  • (BigDecimal)

    The unit price of an item in pounds.

See Also:



21
22
23
# File 'lib/clearbooks/model/item.rb', line 21

def unit_price
  @unit_price
end

#vatString (readonly)

Required. The total amount of VAT in pounds. Use either this field or vat_rate.



36
37
38
# File 'lib/clearbooks/model/item.rb', line 36

def vat
  @vat
end

#vat_rateString (readonly)

Required. The percentage VAT as a decimal number. Use either this field or vat.



41
42
43
# File 'lib/clearbooks/model/item.rb', line 41

def vat_rate
  @vat_rate
end

Instance Method Details

#to_savonHash

Returns self as Savon readable Hash

Returns:

  • (Hash)

    Returns self as Savon readable Hash



63
64
65
66
67
68
69
70
71
72
# File 'lib/clearbooks/model/item.rb', line 63

def to_savon
  {
        :@unitPrice     => @unit_price.to_f,
        :@quantity      => @quantity,
        :@type          => @type,
        :@vat           => @vat,
        :@vatRate       => @vat_rate,
        :description    => @description
  }.compact
end