Class: TimePricing::Plan

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Plan

Returns a new instance of Plan.



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

def initialize(**args)
  @name = args[:name]
  @duration = args[:duration]
  @cost = args[:cost]

  # validate plan data
  if !@name || !@duration.is_a?(Integer) || !@cost.is_a?(Integer)
    raise TimePricing::ParameterMissing.new "Not a valid plan"
  end
end

Instance Attribute Details

#costObject (readonly)

Returns the value of attribute cost.



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

def cost
  @cost
end

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#to_jsonObject



16
17
18
19
20
21
22
# File 'lib/time_pricing/plan.rb', line 16

def to_json
  {
    name: @name,
    duration: @duration,
    cost: @cost
  }
end