Class: CveMonitor::CpeList
- Inherits:
-
Object
- Object
- CveMonitor::CpeList
- Defined in:
- lib/cve_monitor/cpe_list.rb
Instance Attribute Summary collapse
-
#cpes ⇒ Object
readonly
Returns the value of attribute cpes.
Instance Method Summary collapse
- #add!(cpes) ⇒ Object
-
#initialize(path) ⇒ CpeList
constructor
A new instance of CpeList.
- #match?(cpes) ⇒ Boolean
- #remove!(cpes) ⇒ Object
- #save! ⇒ Object
- #to_s ⇒ Object
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
#cpes ⇒ Object (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
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_s ⇒ Object
42 43 44 |
# File 'lib/cve_monitor/cpe_list.rb', line 42 def to_s @cpes.map(&:to_s).join("\n") end |