Class: CVE::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/cve_crawler/cve_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#historyObject

Returns the value of attribute history.



8
9
10
# File 'lib/cve_crawler/cve_filter.rb', line 8

def history
  @history
end

#history_sizeObject

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

Returns:

  • (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_limitObject



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

#inspectObject



31
32
33
# File 'lib/cve_crawler/cve_filter.rb', line 31

def inspect
  "#<CVE::Filter history=#{@history.count} limit=#{@history_size}>"
end