Class: ScanProfileBase

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/metadata/ScanProfile/ScanProfileBase.rb

Direct Known Subclasses

HostScanProfile, VmScanProfile

Constant Summary collapse

DEFINITION =
"definition"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataHash, options = {}) ⇒ ScanProfileBase

Returns a new instance of ScanProfileBase.



14
15
16
17
18
19
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 14

def initialize(dataHash, options = {})
  @params = dataHash
  @options = options
  @xml_class = @options[:xml_class] || XmlHash::Document
  @scan_items = @params[DEFINITION].collect { |s| self.class.scan_item_class.new(s, options) }
end

Instance Attribute Details

#scan_itemsObject

Returns the value of attribute scan_items.



12
13
14
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 12

def scan_items
  @scan_items
end

Class Method Details

.scan_item_classObject



2
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 2

def self.scan_item_class;     ScanProfilesBase.get_class('item',     self); end

.scan_profile_classObject



6
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 6

def self.scan_profile_class;  self; end

.scan_profiles_classObject



4
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 4

def self.scan_profiles_class; ScanProfilesBase.get_class('profiles', self); end

Instance Method Details

#eachObject



21
22
23
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 21

def each
  scan_items.each { |si| yield si }
end

#each_scan_definition(type = nil, &blk) ⇒ Object



25
26
27
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 25

def each_scan_definition(type = nil, &blk)
  scan_items.each { |si| si.with_scan_definition(type, &blk) if type.nil? || type == si.scan_item_type }
end

#each_scan_item(type = nil) ⇒ Object



29
30
31
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 29

def each_scan_item(type = nil)
  scan_items.each { |si| yield si if type.nil? || type == si.scan_item_type }
end

#to_hashObject



40
41
42
43
44
45
46
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 40

def to_hash
  {
    :guid       => @params["guid"],
    :name       => @params["name"],
    :scan_items => collect(&:to_hash)
  }
end

#to_xmlObject



33
34
35
36
37
38
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 33

def to_xml
  xml = @xml_class.newNode("scan_profile")
  xml.add_attributes("guid" => @params["guid"], "name" => @params["name"])
  each { |si| xml << si.to_xml }
  xml
end

#to_yamlObject



48
49
50
# File 'lib/metadata/ScanProfile/ScanProfileBase.rb', line 48

def to_yaml
  YAML.dump(to_hash)
end