Class: CVE::Vulnerability
- Inherits:
-
Object
- Object
- CVE::Vulnerability
- Defined in:
- lib/cve_crawler/cve_vulnerability.rb
Constant Summary collapse
- SOFTWARE_EXTRACT_REGEXP =
Regexp.new('[(, ]([^(), ]+)')
Instance Attribute Summary collapse
-
#affected_software ⇒ Object
readonly
Returns the value of attribute affected_software.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #affected_count ⇒ Object
- #equal?(cve_item, strict = false) ⇒ Boolean
- #extract_software_from_title(title) ⇒ Object
-
#initialize(data) ⇒ Vulnerability
constructor
A new instance of Vulnerability.
- #inspect ⇒ Object
- #malformed?(data) ⇒ Boolean
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Vulnerability
Returns a new instance of Vulnerability.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 5 def initialize(data) unless data.instance_of?(Hash) raise 'CVE Vulnerability needs to be initialized with a hash' end if malformed?(data) raise 'CVE Vulnerability data is malformed' end @identifier = data[:identifier] @date = data[:date] @description = data[:description] @link = data[:link] @title = data[:title] @affected_software = extract_software_from_title(data[:title]) end |
Instance Attribute Details
#affected_software ⇒ Object (readonly)
Returns the value of attribute affected_software.
22 23 24 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 22 def affected_software @affected_software end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
22 23 24 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 22 def date @date end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
22 23 24 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 22 def description @description end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
22 23 24 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 22 def identifier @identifier end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
22 23 24 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 22 def link @link end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
22 23 24 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 22 def title @title end |
Instance Method Details
#affected_count ⇒ Object
39 40 41 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 39 def affected_count @affected_software.nil? ? 0 : @affected_software.count end |
#equal?(cve_item, strict = false) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 43 def equal?(cve_item, strict=false) return false unless cve_item.is_a?(Vulnerability) if strict return @identifier == cve_item.identifier && @link == cve_item.link && @date.utc.iso8601 == cve_item.date.utc.iso8601 && @title == cve_item.title && @description == cve_item.description end @identifier == cve_item.identifier && @link == cve_item.link end |
#extract_software_from_title(title) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 29 def extract_software_from_title(title) software = [] title.scan(SOFTWARE_EXTRACT_REGEXP) do |scan| software << scan[0] end software.count == 0 ? nil : software end |
#inspect ⇒ Object
69 70 71 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 69 def inspect "#<CVE::Vulnerability id=#{@identifier} affected=#{affected_count}>" end |
#malformed?(data) ⇒ Boolean
24 25 26 27 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 24 def malformed?(data) !(data.has_key?(:identifier) && data.has_key?(:date) && data.has_key?(:description) && data.has_key?(:link) && data.has_key?(:title)) end |
#to_hash ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 58 def to_hash { :identifier => @identifier, :title => @title, :link => @link, :description => @description, :date => @date, :affected_software => @affected_software } end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/cve_crawler/cve_vulnerability.rb', line 54 def to_s "#{@title} - #{@link}" end |