Class: DCloud::HardwareProfile::Property

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

Direct Known Subclasses

FloatProperty, IntegerProperty

Defined Under Namespace

Classes: Enum, Range

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, name) ⇒ Property

Returns a new instance of Property.



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dcloud/hardware_profile.rb', line 53

def initialize(xml, name)
  @name = name
  p = REXML::XPath.first(xml, "property[@name = '#{name}']")
  if p
    @value = p.attributes['value']
    @unit = p.attributes['unit']
    @kind = p.attributes['kind']
    @range = Range.new(p.get_elements('range')[0]) if @kind=='range'
    @enum = Enum.new(p.get_elements('enum')[0]) if @kind=='enum'
  end
end

Instance Attribute Details

#enumObject (readonly)

Returns the value of attribute enum.



51
52
53
# File 'lib/dcloud/hardware_profile.rb', line 51

def enum
  @enum
end

#kindObject (readonly)

Returns the value of attribute kind.



51
52
53
# File 'lib/dcloud/hardware_profile.rb', line 51

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



51
52
53
# File 'lib/dcloud/hardware_profile.rb', line 51

def name
  @name
end

#rangeObject (readonly)

Returns the value of attribute range.



51
52
53
# File 'lib/dcloud/hardware_profile.rb', line 51

def range
  @range
end

#unitObject (readonly)

Returns the value of attribute unit.



51
52
53
# File 'lib/dcloud/hardware_profile.rb', line 51

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



51
52
53
# File 'lib/dcloud/hardware_profile.rb', line 51

def value
  @value
end

Instance Method Details

#present?Boolean

Returns:

  • (Boolean)


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

def present?
  ! @value.nil?
end

#to_sObject

FIXME: how to range/enum/kind bits fit into this?



70
71
72
73
74
75
# File 'lib/dcloud/hardware_profile.rb', line 70

def to_s
  v = @value || "---"
  u = @unit || ""
  u = "" if ["label", "count"].include?(u)
  "#{v} #{u}"
end