Module: Stall::Sellable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/stall/sellable.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Create default handlers for the ‘#eot_price` and `#vat_rate` methods that don’t need to be explictly defined if the whole shop has a single VAT rate for all products
44
45
46
47
48
49
50
|
# File 'lib/stall/sellable.rb', line 44
def method_missing(name, *args, &block)
if [:eot_price, :vat_rate].include?(name)
send(:"default_#{ name }")
else
super
end
end
|
Instance Method Details
#currency ⇒ Object
24
25
26
|
# File 'lib/stall/sellable.rb', line 24
def currency
Money.default_currency
end
|
#to_line_item ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/stall/sellable.rb', line 11
def to_line_item
line_items.build(
name: (try(:name) || try(:title)),
unit_price: try(:price),
unit_eot_price: eot_price,
vat_rate: vat_rate,
)
end
|
#vat_ratio ⇒ Object
20
21
22
|
# File 'lib/stall/sellable.rb', line 20
def vat_ratio
(vat_rate / 100.0) + 1
end
|