Class: Zillion::PlanMapper
- Inherits:
-
Object
- Object
- Zillion::PlanMapper
- Defined in:
- lib/zillion/mapper.rb
Instance Attribute Summary collapse
-
#plans ⇒ Object
Returns the value of attribute plans.
Instance Method Summary collapse
- #add(key, plan) ⇒ Object
- #all ⇒ Object
- #all_free ⇒ Object
- #all_paid ⇒ Object
- #del(key) ⇒ Object
- #exists?(key) ⇒ Boolean
- #get(key) ⇒ Object
-
#initialize(specs, opts = {}) ⇒ PlanMapper
constructor
A new instance of PlanMapper.
- #keys ⇒ Object
Constructor Details
#initialize(specs, opts = {}) ⇒ PlanMapper
Returns a new instance of PlanMapper.
109 110 111 112 113 114 115 |
# File 'lib/zillion/mapper.rb', line 109 def initialize(specs, opts = {}) @plans = {} specs.each do |key, spec| add(key, Plan.factory({ key: key }.merge(deep_symbolize_keys(spec)))) end plans.keys end |
Instance Attribute Details
#plans ⇒ Object
Returns the value of attribute plans.
107 108 109 |
# File 'lib/zillion/mapper.rb', line 107 def plans @plans end |
Instance Method Details
#add(key, plan) ⇒ Object
126 127 128 |
# File 'lib/zillion/mapper.rb', line 126 def add(key, plan) @plans[key.to_sym] = plan end |
#all ⇒ Object
117 118 119 120 |
# File 'lib/zillion/mapper.rb', line 117 def all raise "Plans not loaded yet!" if plans.empty? plans end |
#all_free ⇒ Object
144 145 146 |
# File 'lib/zillion/mapper.rb', line 144 def all_free all.select { |plan| plan.is_a?(FreePlan) } end |
#all_paid ⇒ Object
148 149 150 |
# File 'lib/zillion/mapper.rb', line 148 def all_paid all.select { |plan| !plan.is_a?(FreePlan) } end |
#del(key) ⇒ Object
130 131 132 |
# File 'lib/zillion/mapper.rb', line 130 def del(key) plans.delete(key.to_sym) end |
#exists?(key) ⇒ Boolean
140 141 142 |
# File 'lib/zillion/mapper.rb', line 140 def exists?(key) !!plans[key.to_sym] end |
#get(key) ⇒ Object
134 135 136 137 138 |
# File 'lib/zillion/mapper.rb', line 134 def get(key) raise "Please load first. No need to be an ass." if plans.empty? return key if key.is_a?(Plan) plans[key.to_sym] end |
#keys ⇒ Object
122 123 124 |
# File 'lib/zillion/mapper.rb', line 122 def keys plans.keys end |