Class: Zillion::PlanMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/zillion/mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#plansObject

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

#allObject



117
118
119
120
# File 'lib/zillion/mapper.rb', line 117

def all
  raise "Plans not loaded yet!" if plans.empty?
  plans
end

#all_freeObject



144
145
146
# File 'lib/zillion/mapper.rb', line 144

def all_free
  all.select { |plan| plan.is_a?(FreePlan) }
end

#all_paidObject



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

Returns:

  • (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

#keysObject



122
123
124
# File 'lib/zillion/mapper.rb', line 122

def keys
  plans.keys
end