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.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/deltacloud/hardware_profile.rb', line 42

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.



34
35
36
# File 'lib/deltacloud/hardware_profile.rb', line 34

def default
  @default
end

#firstObject (readonly)

kind == :range



36
37
38
# File 'lib/deltacloud/hardware_profile.rb', line 36

def first
  @first
end

#kindObject (readonly)

Returns the value of attribute kind.



34
35
36
# File 'lib/deltacloud/hardware_profile.rb', line 34

def kind
  @kind
end

#lastObject (readonly)

kind == :range



36
37
38
# File 'lib/deltacloud/hardware_profile.rb', line 36

def last
  @last
end

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/deltacloud/hardware_profile.rb', line 34

def name
  @name
end

#valueObject (readonly)

kind == :fixed



40
41
42
# File 'lib/deltacloud/hardware_profile.rb', line 40

def value
  @value
end

#valuesObject (readonly)

kind == :enum



38
39
40
# File 'lib/deltacloud/hardware_profile.rb', line 38

def values
  @values
end

Instance Method Details

#fixed?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/deltacloud/hardware_profile.rb', line 69

def fixed?
  kind == :fixed
end

#include?(v) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
# File 'lib/deltacloud/hardware_profile.rb', line 84

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



65
66
67
# File 'lib/deltacloud/hardware_profile.rb', line 65

def param
  "hwp_#{name}"
end

#to_paramObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/deltacloud/hardware_profile.rb', line 73

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



61
62
63
# File 'lib/deltacloud/hardware_profile.rb', line 61

def unit
  HardwareProfile.unit(name)
end