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.
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
#default ⇒ Object (readonly)
Returns the value of attribute default.
17 18 19 |
# File 'lib/deltacloud/hardware_profile.rb', line 17 def default @default end |
#first ⇒ Object (readonly)
kind == :range
19 20 21 |
# File 'lib/deltacloud/hardware_profile.rb', line 19 def first @first end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
17 18 19 |
# File 'lib/deltacloud/hardware_profile.rb', line 17 def kind @kind end |
#last ⇒ Object (readonly)
kind == :range
19 20 21 |
# File 'lib/deltacloud/hardware_profile.rb', line 19 def last @last end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/deltacloud/hardware_profile.rb', line 17 def name @name end |
#value ⇒ Object (readonly)
kind == :fixed
23 24 25 |
# File 'lib/deltacloud/hardware_profile.rb', line 23 def value @value end |
#values ⇒ Object (readonly)
kind == :enum
21 22 23 |
# File 'lib/deltacloud/hardware_profile.rb', line 21 def values @values end |
Instance Method Details
#fixed? ⇒ Boolean
52 53 54 |
# File 'lib/deltacloud/hardware_profile.rb', line 52 def fixed? kind == :fixed end |
#include?(v) ⇒ 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 |
#param ⇒ Object
48 49 50 |
# File 'lib/deltacloud/hardware_profile.rb', line 48 def param "hwp_#{name}" end |
#to_param ⇒ Object
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 |
#unit ⇒ Object
44 45 46 |
# File 'lib/deltacloud/hardware_profile.rb', line 44 def unit HardwareProfile.unit(name) end |