Class: CveMonitor::CpeList

Inherits:
Object
  • Object
show all
Defined in:
lib/cve_monitor/cpe_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ CpeList

Returns a new instance of CpeList.



7
8
9
10
11
12
13
14
15
16
# File 'lib/cve_monitor/cpe_list.rb', line 7

def initialize(path)
  @path = path
  @cpes = if File.exist?(path)
            File.open(path).map do |line|
              Cpe23.parse(line)
            end
          else
            []
          end
end

Instance Attribute Details

#cpesObject (readonly)

Returns the value of attribute cpes.



5
6
7
# File 'lib/cve_monitor/cpe_list.rb', line 5

def cpes
  @cpes
end

Instance Method Details

#add!(cpes) ⇒ Object



18
19
20
# File 'lib/cve_monitor/cpe_list.rb', line 18

def add!(cpes)
  @cpes += ensure_cpes(cpes)
end

#match?(cpes) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/cve_monitor/cpe_list.rb', line 36

def match?(cpes)
  cpes.select do |cpe|
    @cpes.any? { |e| e == cpe }
  end
end

#remove!(cpes) ⇒ Object



22
23
24
25
26
# File 'lib/cve_monitor/cpe_list.rb', line 22

def remove!(cpes)
  ensure_cpes(cpes).each do |cpe|
    @cpes.reject! { |e| e == cpe }
  end
end

#save!Object



28
29
30
31
32
33
34
# File 'lib/cve_monitor/cpe_list.rb', line 28

def save!
  File.open(@path, 'w') do |file|
    @cpes.each do |cpe|
      file.write("#{cpe.to_str}\n")
    end
  end
end

#to_sObject



42
43
44
# File 'lib/cve_monitor/cpe_list.rb', line 42

def to_s
  @cpes.map(&:to_s).join("\n")
end