Class: SubscriptionFu::Plan

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::NumberHelper, Comparable
Defined in:
app/models/subscription_fu/plan.rb

Constant Summary collapse

TAX =
0.05

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, price, data = {}) ⇒ Plan

Returns a new instance of Plan.



10
11
12
13
14
# File 'app/models/subscription_fu/plan.rb', line 10

def initialize(key, price, data = {})
  self.key = key
  self.price = price
  data.each {|k,v| self.send("#{k}=", v) }
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



7
8
9
# File 'app/models/subscription_fu/plan.rb', line 7

def key
  @key
end

#priceObject

Returns the value of attribute price.



8
9
10
# File 'app/models/subscription_fu/plan.rb', line 8

def price
  @price
end

Instance Method Details

#<=>(other) ⇒ Object



40
41
42
# File 'app/models/subscription_fu/plan.rb', line 40

def <=>(other)
  price <=> other.price
end

#currencyObject



36
37
38
# File 'app/models/subscription_fu/plan.rb', line 36

def currency
  "JPY"
end

#free_plan?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/subscription_fu/plan.rb', line 24

def free_plan?
  price == 0
end

#human_nameObject



16
17
18
# File 'app/models/subscription_fu/plan.rb', line 16

def human_name
  I18n.t(key, :scope => [:subscription_fu, :plan, :options])
end

#human_priceObject



20
21
22
# File 'app/models/subscription_fu/plan.rb', line 20

def human_price
  number_to_currency(price_with_tax)
end

#price_taxObject



32
33
34
# File 'app/models/subscription_fu/plan.rb', line 32

def price_tax
  (price * TAX).to_i
end

#price_with_taxObject



28
29
30
# File 'app/models/subscription_fu/plan.rb', line 28

def price_with_tax
  (price * (1.0 + TAX)).to_i
end