Class: Deltacloud::HardwareProfile::Property
- Inherits:
-
Object
- Object
- Deltacloud::HardwareProfile::Property
- Defined in:
- lib/deltacloud/hardware_profile.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#first ⇒ Object
readonly
kind == :range.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#last ⇒ Object
readonly
kind == :range.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
kind == :fixed.
-
#values ⇒ Object
readonly
kind == :enum.
Instance Method Summary collapse
- #fixed? ⇒ Boolean
- #include?(v) ⇒ Boolean
-
#initialize(name, values, opts = {}) ⇒ Property
constructor
A new instance of Property.
- #param ⇒ Object
- #to_param ⇒ Object
- #unit ⇒ Object
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
#default ⇒ Object (readonly)
Returns the value of attribute default.
34 35 36 |
# File 'lib/deltacloud/hardware_profile.rb', line 34 def default @default end |
#first ⇒ Object (readonly)
kind == :range
36 37 38 |
# File 'lib/deltacloud/hardware_profile.rb', line 36 def first @first end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
34 35 36 |
# File 'lib/deltacloud/hardware_profile.rb', line 34 def kind @kind end |
#last ⇒ Object (readonly)
kind == :range
36 37 38 |
# File 'lib/deltacloud/hardware_profile.rb', line 36 def last @last end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/deltacloud/hardware_profile.rb', line 34 def name @name end |
#value ⇒ Object (readonly)
kind == :fixed
40 41 42 |
# File 'lib/deltacloud/hardware_profile.rb', line 40 def value @value end |
#values ⇒ Object (readonly)
kind == :enum
38 39 40 |
# File 'lib/deltacloud/hardware_profile.rb', line 38 def values @values end |
Instance Method Details
#fixed? ⇒ Boolean
69 70 71 |
# File 'lib/deltacloud/hardware_profile.rb', line 69 def fixed? kind == :fixed end |
#include?(v) ⇒ 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 |
#param ⇒ Object
65 66 67 |
# File 'lib/deltacloud/hardware_profile.rb', line 65 def param "hwp_#{name}" end |
#to_param ⇒ Object
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 |
#unit ⇒ Object
61 62 63 |
# File 'lib/deltacloud/hardware_profile.rb', line 61 def unit HardwareProfile.unit(name) end |