Class: Docdata::LineItem
- Inherits:
-
Object
- Object
- Docdata::LineItem
- Defined in:
- lib/docdata/line_item.rb
Overview
Object representing a "LineItem"
@note Warning: do not use this part of the gem, for it will break. Be warned!
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#description ⇒ Object
Returns the value of attribute description.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#image ⇒ Object
Returns the value of attribute image.
-
#name ⇒ Object
Returns the value of attribute name.
-
#price_per_unit ⇒ Object
Returns the value of attribute price_per_unit.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#unit_of_measure ⇒ Object
Returns the value of attribute unit_of_measure.
-
#vat_included ⇒ Object
Returns the value of attribute vat_included.
-
#vat_rate ⇒ Object
Returns the value of attribute vat_rate.
Instance Method Summary collapse
-
#error_message ⇒ String
The string that contains all the errors for this line_item.
- #gross_amount ⇒ Object
-
#initialize(args = nil) ⇒ LineItem
constructor
Initializer to transform a +Hash+ into an LineItem object.
- #nett_amount ⇒ Object
-
#total_price ⇒ Integer
Total price of this line item.
-
#valid? ⇒ Boolean
True/false, depending if this instanciated object is valid.
-
#vat ⇒ Integer
based on the vat_rate, quantity and price_per_unit.
Constructor Details
#initialize(args = nil) ⇒ LineItem
Initializer to transform a +Hash+ into an LineItem object
47 48 49 50 51 52 53 54 55 |
# File 'lib/docdata/line_item.rb', line 47 def initialize(args=nil) @unit_of_measure = "PCS" @vat_rate = 0 @vat_included = true return if args.nil? args.each do |k,v| instance_variable_set("@#{k}", v) unless v.nil? end end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
34 35 36 |
# File 'lib/docdata/line_item.rb', line 34 def code @code end |
#description ⇒ Object
Returns the value of attribute description.
37 38 39 |
# File 'lib/docdata/line_item.rb', line 37 def description @description end |
#errors ⇒ Object
Returns the value of attribute errors.
32 33 34 |
# File 'lib/docdata/line_item.rb', line 32 def errors @errors end |
#image ⇒ Object
Returns the value of attribute image.
38 39 40 |
# File 'lib/docdata/line_item.rb', line 38 def image @image end |
#name ⇒ Object
Returns the value of attribute name.
33 34 35 |
# File 'lib/docdata/line_item.rb', line 33 def name @name end |
#price_per_unit ⇒ Object
Returns the value of attribute price_per_unit.
39 40 41 |
# File 'lib/docdata/line_item.rb', line 39 def price_per_unit @price_per_unit end |
#quantity ⇒ Object
Returns the value of attribute quantity.
35 36 37 |
# File 'lib/docdata/line_item.rb', line 35 def quantity @quantity end |
#unit_of_measure ⇒ Object
Returns the value of attribute unit_of_measure.
36 37 38 |
# File 'lib/docdata/line_item.rb', line 36 def unit_of_measure @unit_of_measure end |
#vat_included ⇒ Object
Returns the value of attribute vat_included.
41 42 43 |
# File 'lib/docdata/line_item.rb', line 41 def vat_included @vat_included end |
#vat_rate ⇒ Object
Returns the value of attribute vat_rate.
40 41 42 |
# File 'lib/docdata/line_item.rb', line 40 def vat_rate @vat_rate end |
Instance Method Details
#error_message ⇒ String
Returns the string that contains all the errors for this line_item.
64 65 66 |
# File 'lib/docdata/line_item.rb', line 64 def "One of your line_items is invalid. Error messages: #{errors..join(', ')}" end |
#gross_amount ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/docdata/line_item.rb', line 73 def gross_amount if vat_included total_price else total_price + vat end end |
#nett_amount ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/docdata/line_item.rb', line 81 def nett_amount if vat_included total_price - vat else total_vat end end |
#total_price ⇒ Integer
Returns total price of this line item.
69 70 71 |
# File 'lib/docdata/line_item.rb', line 69 def total_price price_per_unit * quantity end |
#valid? ⇒ Boolean
Returns true/false, depending if this instanciated object is valid.
58 59 60 61 |
# File 'lib/docdata/line_item.rb', line 58 def valid? validator = LineItemValidator.new validator.valid?(self) end |
#vat ⇒ Integer
based on the vat_rate, quantity and price_per_unit
91 92 93 94 95 96 97 |
# File 'lib/docdata/line_item.rb', line 91 def vat if vat_included ((gross_amount.to_f * "1.#{vat_rate.to_s.gsub('.','')}".to_f) - gross_amount) * -1 else ((nett_amount.to_f * "1.#{vat_rate.to_s.gsub('.','')}".to_f) - nett_amount) end end |