class Deltacloud::HardwareProfile

Constants

UNITS

Attributes

name[RW]

Public Class Methods

new(profile_id, &block) click to toggle source
Calls superclass method Deltacloud::BaseModel.new
# File lib/deltacloud/models/hardware_profile.rb, line 51
def initialize(profile_id, &block)
  @properties   = {}
  super(:id => profile_id)
  result = instance_eval(&block) if block_given?
  @name ||= profile_id
  result
end
property(prop) click to toggle source
# File lib/deltacloud/models/hardware_profile.rb, line 32
def property(prop)
  define_method(prop) do |*args|
    values, opts, _ = *args
    unless values.nil?
      @properties[prop] = Property.new(prop, values, opts || {})
    end
    @properties[prop]
  end
end
unit(name) click to toggle source
# File lib/deltacloud/models/hardware_profile.rb, line 27
def self.unit(name)
  UNITS[name]
end

Public Instance Methods

default?(prop, v) click to toggle source
# File lib/deltacloud/models/hardware_profile.rb, line 71
def default?(prop, v)
  property(prop) && property(prop).default.to_s == v
end
each_property() { |prop| ... } click to toggle source
# File lib/deltacloud/models/hardware_profile.rb, line 59
def each_property(&block)
  @properties.each_value { |prop| yield prop }
end
include?(prop, v) click to toggle source
# File lib/deltacloud/models/hardware_profile.rb, line 75
def include?(prop, v)
  return false unless p = property(prop)
  return true if p.kind == :range and (p.first..p.last).include?(v)
  return true if p.kind == :enum and p.values.include?(v)
  return true if p.kind == :fixed and p.value == v
  false
end
params() click to toggle source
# File lib/deltacloud/models/hardware_profile.rb, line 83
def params
  @properties.values.inject([]) { |m, prop|
    m << prop.to_param
  }.compact
end
properties() click to toggle source
# File lib/deltacloud/models/hardware_profile.rb, line 63
def properties
  @properties.values
end
property(name) click to toggle source
# File lib/deltacloud/models/hardware_profile.rb, line 67
def property(name)
  @properties[name.to_sym]
end
to_hash(context) click to toggle source
# File lib/deltacloud/models/hardware_profile.rb, line 89
def to_hash(context)
  r = {
    :id => self.id,
    :href => context.hardware_profile_url(self.id),
    :name => name,
  }
  r.merge!({:properties => @properties}) if !@properties.empty?
  r
end