Class: CIM::Qualifier

Inherits:
Object
  • Object
show all
Defined in:
lib/cim/qualifier.rb

Overview

A Qualifier is a modifier containing information to describe a Class, an Instance, a Property, a Method or a parameter.

Qualifier can be seen as an instance of QualifierDeclaration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(declaration, value = nil, flavor = nil) ⇒ Qualifier

call-seq:

Qualifier.new qualifier_declaration
Qualifier.new qualifier_declaration, value
Qualifier.new qualifier_declaration, value, flavor


29
30
31
32
33
34
35
# File 'lib/cim/qualifier.rb', line 29

def initialize declaration, value = nil, flavor = nil
  raise "Not a CIM::QualifierDeclaration: #{declaration.inspect}" unless declaration.is_a?(CIM::QualifierDeclaration)
  @declaration = declaration
  # FIXME, check if the value type matches the declaration type
  @value = value
  @flavor = flavor
end

Instance Attribute Details

#declarationObject (readonly)

Returns the value of attribute declaration.



22
23
24
# File 'lib/cim/qualifier.rb', line 22

def declaration
  @declaration
end

#flavorObject (readonly)

Returns the value of attribute flavor.



22
23
24
# File 'lib/cim/qualifier.rb', line 22

def flavor
  @flavor
end

#valueObject (readonly)

Returns the value of attribute value.



22
23
24
# File 'lib/cim/qualifier.rb', line 22

def value
  @value
end

Class Method Details

.normalize(type) ⇒ Object



18
19
20
# File 'lib/cim/qualifier.rb', line 18

def self.normalize type
  (type.is_a? self) ? type : self.new(type)
end

Instance Method Details

#==(q) ⇒ Object

Check for equality against Qualifier, QualifierDeclaration, String, or Symbol



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cim/qualifier.rb', line 39

def == q
  #	puts "CIM::Qualifier ->#{self} == #{q.inspect}"
  case q
  when CIM::Qualifier
	(@declaration == q.declaration) &&
	(@value == q.value) &&
	(@flavor == q.flavor)
  when CIM::QualifierDeclaration
	@declaration == q  
  when String
	@declaration.name.downcase == q.downcase && @value.nil? && @flavor.nil?
  when Symbol
	self == q.to_s # recycle
  else
	false
  end
end

#nameObject

Name of qualifier (String)



59
60
61
# File 'lib/cim/qualifier.rb', line 59

def name
  @declaration.name
end

#to_sObject

returns a string representation in MOF syntax format



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cim/qualifier.rb', line 77

def to_s
  s = "#{@declaration.name.capitalize}"
  case @value
  when nil
  when Array
	s << " {#{@value.join(', ')}}"
  else
	s << "(#{@value.inspect})"
  end
  s << " #{@flavor}" if @flavor
  s
end

#to_symObject

Name of qualifier as symbol (Symbol)



71
72
73
# File 'lib/cim/qualifier.rb', line 71

def to_sym
  @declaration.to_sym
end

#typeObject

Type of qualifier (Type)



65
66
67
# File 'lib/cim/qualifier.rb', line 65

def type
  @declaration.type
end