Class: Deltacloud::HardwareProfile::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/deltacloud/hardware_profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, values, opts = {}) ⇒ Property

Returns a new instance of Property.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/deltacloud/hardware_profile.rb', line 25

def initialize(name, values, opts = {})
  @name = name
  if values.is_a?(Range)
    @kind = :range
    @first = values.first
    @last = values.last
    @default = values.first
  elsif values.is_a?(Array)
    @kind = :enum
    @values = values
    @default = values.first
  else
    @kind = :fixed
    @value = values
    @default = @value
  end
  @default = opts[:default] if opts[:default]
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



17
18
19
# File 'lib/deltacloud/hardware_profile.rb', line 17

def default
  @default
end

#firstObject (readonly)

kind == :range



19
20
21
# File 'lib/deltacloud/hardware_profile.rb', line 19

def first
  @first
end

#kindObject (readonly)

Returns the value of attribute kind.



17
18
19
# File 'lib/deltacloud/hardware_profile.rb', line 17

def kind
  @kind
end

#lastObject (readonly)

kind == :range



19
20
21
# File 'lib/deltacloud/hardware_profile.rb', line 19

def last
  @last
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/deltacloud/hardware_profile.rb', line 17

def name
  @name
end

#valueObject (readonly)

kind == :fixed



23
24
25
# File 'lib/deltacloud/hardware_profile.rb', line 23

def value
  @value
end

#valuesObject (readonly)

kind == :enum



21
22
23
# File 'lib/deltacloud/hardware_profile.rb', line 21

def values
  @values
end

Instance Method Details

#fixed?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/deltacloud/hardware_profile.rb', line 52

def fixed?
  kind == :fixed
end

#include?(v) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
# File 'lib/deltacloud/hardware_profile.rb', line 67

def include?(v)
  if kind == :fixed
    return v == value
  elsif kind == :range
    return v >= first && v <= last
  else
    return values.include?(v)
  end
end

#paramObject



48
49
50
# File 'lib/deltacloud/hardware_profile.rb', line 48

def param
  "hwp_#{name}"
end

#to_paramObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/deltacloud/hardware_profile.rb', line 56

def to_param
  return nil if kind == :fixed
  if kind == :range
    # FIXME: We can't validate ranges currently
    args = [param, :string, :optional]
  else
    args = [param, :string, :optional, values.collect { |v| v.to_s} ]
  end
  Validation::Param.new(args)
end

#unitObject



44
45
46
# File 'lib/deltacloud/hardware_profile.rb', line 44

def unit
  HardwareProfile.unit(name)
end