Class: GProv::Provision::EntryBase::XMLAttr

Inherits:
Object
  • Object
show all
Defined in:
lib/gprov/provision/entrybase/xmlattr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ XMLAttr

Returns a new instance of XMLAttr.



40
41
42
43
44
# File 'lib/gprov/provision/entrybase/xmlattr.rb', line 40

def initialize(name, options={})
  @name = name
  @type = :string
  methodhash(options)
end

Instance Attribute Details

#nameObject (readonly)

The name attribute is not used by this class, but is used by calling classes to determine the method/attribute name they’ll use to associate with this object.



38
39
40
# File 'lib/gprov/provision/entrybase/xmlattr.rb', line 38

def name
  @name
end

Instance Method Details

#parse(xml) ⇒ Object

Given an XML document, use the supplied xpath value to extract the desired value for this attribute from the document.



64
65
66
67
# File 'lib/gprov/provision/entrybase/xmlattr.rb', line 64

def parse(xml)
  @value = xml.at_xpath(@xpath).to_s
  format
end

#type(val = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/gprov/provision/entrybase/xmlattr.rb', line 51

def type(val=nil)

  if [:numeric, :string, :bool].include? val
    @type = val
  else
    raise ArgumentError, "#{@type} is not recognized as a valid format type"
  end

  @type
end

#xpath(val = nil) ⇒ Object



46
47
48
49
# File 'lib/gprov/provision/entrybase/xmlattr.rb', line 46

def xpath(val=nil)
  @xpath = val if val
  @xpath
end