Class: Coreimpact::Vulnerability
- Inherits:
-
Object
- Object
- Coreimpact::Vulnerability
- Defined in:
- lib/coreimpact/vulnerability.rb
Instance Method Summary collapse
-
#initialize(xml_vulnerability) ⇒ Vulnerability
constructor
A new instance of Vulnerability.
-
#method_missing(method, *args) ⇒ Object
Example XML: <property type=“container” key=“Vulnerabilities”> <property type=“container” key=“CVE-1999-0516”> <property type=“container” key=“Modules”> <property type=“container” key=“<Title>”> <property type=“string” key=“description”> Some description.
- #respond_to?(method, include_private = false) ⇒ Boolean
- #supported_tags ⇒ Object
Constructor Details
#initialize(xml_vulnerability) ⇒ Vulnerability
Returns a new instance of Vulnerability.
3 4 5 |
# File 'lib/coreimpact/vulnerability.rb', line 3 def initialize(xml_vulnerability) @xml = xml_vulnerability end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Example XML: <property type=“container” key=“Vulnerabilities”>
<property type="container" key="CVE-1999-0516">
<property type="container" key="Modules">
<property type="container" key="<Title>">
<property type="string" key="description">
Some description.
</property>
</property>
</property>
</property>
</property>
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/coreimpact/vulnerability.rb', line 29 def method_missing(method, *args) # We could remove this check and return nil for any non-recognized tag. # The problem would be that it would make tricky to debug problems with # typos. For instance: <>.potr would return nil instead of raising an # exception unless .include?(method) super return end result = case method when :cve @xml.first_element_child['key'] when :title @xml.at_xpath('./property/property[@key="Modules"]/property[@type="container"]')['key'] else @xml.at_xpath("./property/property[@key='Modules']/property[@type='container']/property[@key='#{method}']").text end result || 'n/a' end |
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
11 12 13 14 15 |
# File 'lib/coreimpact/vulnerability.rb', line 11 def respond_to?(method, include_private = false) return true if .include?(method.to_sym) super end |
#supported_tags ⇒ Object
7 8 9 |
# File 'lib/coreimpact/vulnerability.rb', line 7 def [:agent_deployed, :cve, :description, :port, :tried_to_install_agent, :title] end |