Class: TimePricing::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/time_pricing/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/time_pricing/config.rb', line 5

def initialize(**args)
  @combine_plans = args[:combine_plans] || args[:combine_plans] == nil

  @plans = {}

  if args[:cache].is_a?(Hash)
    @cache = args[:cache]
  else
    @cache = {}
  end
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



3
4
5
# File 'lib/time_pricing/config.rb', line 3

def cache
  @cache
end

#combine_plansObject

Returns the value of attribute combine_plans.



3
4
5
# File 'lib/time_pricing/config.rb', line 3

def combine_plans
  @combine_plans
end

#plansObject

Returns the value of attribute plans.



3
4
5
# File 'lib/time_pricing/config.rb', line 3

def plans
  @plans
end

Instance Method Details

#add_plan!(**args) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/time_pricing/config.rb', line 21

def add_plan!(**args)
  plan = Plan.new(args)

  # clear cache as plans change
  clear_cache!

  @plans[plan.name] = plan
end

#clear_cache!Object



17
18
19
# File 'lib/time_pricing/config.rb', line 17

def clear_cache!
  @cache = {}
end

#combine_plans?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/time_pricing/config.rb', line 36

def combine_plans?
  @combine_plans
end

#remove_plan!(name) ⇒ Object



30
31
32
33
34
# File 'lib/time_pricing/config.rb', line 30

def remove_plan!(name)
  # clear cache as plans change
  clear_cache!
  @plans.delete(name)
end