Class: VCAP::Services::Plan

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Plan

Returns a new instance of Plan.



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

def initialize(options)
  @unique_id = options.fetch(:unique_id)
  @guid = options[:guid]
  @name = options[:name]
  @description = options[:description]
  @free = options[:free]
  @extra = options[:extra]
  @public = options.fetch(:public, true)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#extraObject (readonly)

Returns the value of attribute extra.



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

def extra
  @extra
end

#freeObject (readonly)

Returns the value of attribute free.



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

def free
  @free
end

#guidObject

Returns the value of attribute guid.



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

def guid
  @guid
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#unique_idObject (readonly)

Returns the value of attribute unique_id.



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

def unique_id
  @unique_id
end

Class Method Details

.plan_hash_as_plan_array(plans) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/base/plan.rb', line 41

def self.plan_hash_as_plan_array(plans)
  plan_array = []
  return plan_array unless plans
  if plans.first.is_a?(Plan)
    return plans
  else
    plans.each do |_, v|
      plan_array << Plan.new(v)
    end
  end
  plan_array
end

.plans_array_to_hash(plans_array) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/base/plan.rb', line 54

def self.plans_array_to_hash(plans_array)
  return [] unless plans_array
  plans_array_hash = []
  plans_array.each do |plan|
    plans_array_hash << plan.to_hash
  end
  plans_array_hash
end

Instance Method Details

#get_add_hash(service_guid) ⇒ Object



35
36
37
38
39
# File 'lib/base/plan.rb', line 35

def get_add_hash(service_guid)
  plan_as_hash = self.to_hash
  plan_as_hash['service_guid'] = service_guid
  return plan_as_hash
end

#get_update_hash(service_guid) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/base/plan.rb', line 27

def get_update_hash(service_guid)
  plan_as_hash = self.to_hash
  plan_as_hash['service_guid'] = service_guid
  plan_as_hash.delete('unique_id')
  plan_as_hash.delete('public')
  return plan_as_hash
end

#to_hashObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/base/plan.rb', line 16

def to_hash
  {
    'unique_id' => @unique_id,
    'name' => @name,
    'description' => @description,
    'free' => @free,
    'extra' => @extra,
    'public' => @public,
  }
end