Class: ScanItemBase

Inherits:
Object
  • Object
show all
Defined in:
lib/metadata/ScanProfile/ScanItemBase.rb

Direct Known Subclasses

HostScanItem, VmScanItem

Constant Summary collapse

SCAN_TYPE_PROP =
"item_type"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ScanItemBase.



12
13
14
15
16
17
18
19
20
21
# File 'lib/metadata/ScanProfile/ScanItemBase.rb', line 12

def initialize(dataHash, options = {})
  @params = dataHash
  @options = options
  @xml_class = @options[:xml_class] || XmlHash::Document

  @scan_item_type = @params[SCAN_TYPE_PROP]
  extend_scan_module(@scan_item_type)

  @scan_definition = @params[ScanProfileBase::DEFINITION]
end

Instance Attribute Details

#scan_definitionObject

Returns the value of attribute scan_definition.



4
5
6
# File 'lib/metadata/ScanProfile/ScanItemBase.rb', line 4

def scan_definition
  @scan_definition
end

#scan_item_typeObject

Returns the value of attribute scan_item_type.



4
5
6
# File 'lib/metadata/ScanProfile/ScanItemBase.rb', line 4

def scan_item_type
  @scan_item_type
end

Class Method Details

.scan_item_classObject



10
# File 'lib/metadata/ScanProfile/ScanItemBase.rb', line 10

def self.scan_item_class;     self; end

.scan_profile_classObject



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

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

.scan_profiles_classObject



8
# File 'lib/metadata/ScanProfile/ScanItemBase.rb', line 8

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

Instance Method Details

#extend_scan_module(type) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/metadata/ScanProfile/ScanItemBase.rb', line 23

def extend_scan_module(type)
  raise "Already set scan module" if @extend_scan_module
  begin
    m = "#{self.class.name}#{type.capitalize}"
    require_relative "modules/#{m}"
    extend Object.const_get(m)
  rescue LoadError
  end
  @extend_scan_module = true
end

#parse_data(_obj, _data, &_blk) ⇒ Object



60
61
62
# File 'lib/metadata/ScanProfile/ScanItemBase.rb', line 60

def parse_data(_obj, _data, &_blk)
  nil
end

#to_hashObject



48
49
50
51
52
53
54
# File 'lib/metadata/ScanProfile/ScanItemBase.rb', line 48

def to_hash
  {
    :guid      => @params["guid"],
    :name      => @params["name"],
    :item_type => @params["item_type"]
  }
end

#to_xmlObject

THESE METHODS SHOULD BE OVER-RIDDEN BY THE REQUIRES IN THE INITIALIZER



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

def to_xml
  xml = @xml_class.newNode("scan_item")
  xml.add_attributes(
    "guid"      => @params["guid"],
    "name"      => @params["name"],
    "item_type" => @params["item_type"])
  xml
end

#to_yamlObject



56
57
58
# File 'lib/metadata/ScanProfile/ScanItemBase.rb', line 56

def to_yaml
  YAML.dump(to_hash)
end

#with_scan_definition(type = nil) {|scan_definition| ... } ⇒ Object

Yields:



34
35
36
# File 'lib/metadata/ScanProfile/ScanItemBase.rb', line 34

def with_scan_definition(type = nil)
  yield scan_definition if type.nil? || type == scan_item_type
end