Class: ScanProfilesBase

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

Direct Known Subclasses

HostScanProfiles, VmScanProfiles

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ScanProfilesBase.



24
25
26
27
28
29
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 24

def initialize(dataHash, options = {})
  @params = dataHash
  @options = options
  @xml_class = @options[:xml_class] || XmlHash::Document
  @profiles = @params.nil? ? [] : @params.collect { |p| self.class.scan_profile_class.new(p, @options) }
end

Instance Attribute Details

#profilesObject

Returns the value of attribute profiles.



22
23
24
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 22

def profiles
  @profiles
end

Class Method Details

.get_class(type, from) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 5

def self.get_class(type, from)
  k = from.instance_variable_get("@scan_#{type}_class")
  return k unless k.nil?

  k = "#{from.name.underscore.split('_')[0..-2].join('_').camelize}#{type.camelize}"
  require "metadata/ScanProfile/#{k}"
  from.instance_variable_set("@scan_#{type}_class", Object.const_get(k))
end

.scan_item_classObject



14
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 14

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

.scan_profile_classObject



16
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 16

def self.scan_profile_class;  get_class('profile', self); end

.scan_profiles_classObject



18
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 18

def self.scan_profiles_class; self; end

Instance Method Details

#eachObject



31
32
33
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 31

def each
  profiles.each { |p| yield p }
end

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



35
36
37
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 35

def each_scan_definition(type = nil, &blk)
  profiles.each { |p| p.each_scan_definition(type, &blk) }
end

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



39
40
41
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 39

def each_scan_item(type = nil, &blk)
  profiles.each { |p| p.each_scan_item(type, &blk) }
end

#parse_data(obj, data, &blk) ⇒ Object



43
44
45
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 43

def parse_data(obj, data, &blk)
  each_scan_item { |si| si.parse_data(obj, data, &blk) }
end

#to_hashObject



53
54
55
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 53

def to_hash
  {:scan_profiles => collect(&:to_hash)}
end

#to_xmlObject



47
48
49
50
51
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 47

def to_xml
  xml = @xml_class.createDoc("<scan_profiles/>")
  each { |p| xml.root << p.to_xml }
  xml
end

#to_yamlObject



57
58
59
# File 'lib/metadata/ScanProfile/ScanProfilesBase.rb', line 57

def to_yaml
  YAML.dump(to_hash)
end