Class: CVE::Filter
- Inherits:
-
Object
- Object
- CVE::Filter
- Defined in:
- lib/cve_crawler/cve_filter.rb
Instance Attribute Summary collapse
-
#history ⇒ Object
Returns the value of attribute history.
-
#history_size ⇒ Object
Returns the value of attribute history_size.
Instance Method Summary collapse
- #cve_exists?(identifier) ⇒ Boolean
- #filter(contents) ⇒ Object
- #history_check_limit ⇒ Object
-
#initialize(history_size = 100) ⇒ Filter
constructor
A new instance of Filter.
- #inspect ⇒ Object
Constructor Details
#initialize(history_size = 100) ⇒ Filter
Returns a new instance of Filter.
3 4 5 6 |
# File 'lib/cve_crawler/cve_filter.rb', line 3 def initialize(history_size=100) @history = [] @history_size = history_size end |
Instance Attribute Details
#history ⇒ Object
Returns the value of attribute history.
8 9 10 |
# File 'lib/cve_crawler/cve_filter.rb', line 8 def history @history end |
#history_size ⇒ Object
Returns the value of attribute history_size.
8 9 10 |
# File 'lib/cve_crawler/cve_filter.rb', line 8 def history_size @history_size end |
Instance Method Details
#cve_exists?(identifier) ⇒ Boolean
18 19 20 21 22 23 |
# File 'lib/cve_crawler/cve_filter.rb', line 18 def cve_exists?(identifier) return true if @history.include?(identifier) @history << identifier false end |
#filter(contents) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/cve_crawler/cve_filter.rb', line 10 def filter(contents) return true unless contents.is_a?(Vulnerability) return true if cve_exists?(contents.identifier) history_check_limit false end |
#history_check_limit ⇒ Object
25 26 27 28 29 |
# File 'lib/cve_crawler/cve_filter.rb', line 25 def history_check_limit if @history.length > @history_size @history = @history.drop(@history.length - @history_size) end end |
#inspect ⇒ Object
31 32 33 |
# File 'lib/cve_crawler/cve_filter.rb', line 31 def inspect "#<CVE::Filter history=#{@history.count} limit=#{@history_size}>" end |