class DeltaCloud::HWP::Property

Attributes

kind[R]
name[R]
unit[R]
value[R]

Public Class Methods

new(xml, name) click to toggle source
# File lib/hwp_properties.rb, line 23
def initialize(xml, name)
  @name, @kind, @value, @unit = xml['name'], xml['kind'].to_sym, xml['value'], xml['unit']
  declare_ranges(xml)
  self
end

Public Instance Methods

present?() click to toggle source
# File lib/hwp_properties.rb, line 29
def present?
  ! @value.nil?
end

Private Instance Methods

declare_ranges(xml) click to toggle source
# File lib/hwp_properties.rb, line 35
def declare_ranges(xml)
  case xml['kind']
    when 'range' then
      self.class.instance_eval do
        attr_reader :range
      end
      @range = { :from => xml.xpath('range').first['first'], :to => xml.xpath('range').first['last'] }
    when 'enum' then
      self.class.instance_eval do
        attr_reader :options
      end
      @options = xml.xpath('enum/entry').collect { |e| e['value'] }
  end
end