Class: YDIM::Item
- Inherits:
-
Object
- Object
- YDIM::Item
- Defined in:
- lib/ydim/item.rb
Constant Summary collapse
- DATA_KEYS =
[ :data, :expiry_time, :item_type, :price, :quantity, :text, :time, :unit, :vat_rate ]
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Item
constructor
A new instance of Item.
- #total_brutto ⇒ Object
- #total_netto ⇒ Object
- #update(data) ⇒ Object
- #vat ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ Item
Returns a new instance of Item.
9 10 11 |
# File 'lib/ydim/item.rb', line 9 def initialize(data={}) update(data) end |
Instance Method Details
#total_brutto ⇒ Object
12 13 14 |
# File 'lib/ydim/item.rb', line 12 def total_brutto total_netto + vat end |
#total_netto ⇒ Object
15 16 17 |
# File 'lib/ydim/item.rb', line 15 def total_netto @quantity.to_f * @price.to_f end |
#update(data) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ydim/item.rb', line 18 def update(data) data.each { |key, val| if(DATA_KEYS.include?(key.to_sym)) instance_variable_set("@#{key}", val) end } end |
#vat ⇒ Object
25 26 27 |
# File 'lib/ydim/item.rb', line 25 def vat total_netto * (@vat_rate.to_f / 100.0) end |