Class: CVEList::RangeDir
- Includes:
- Enumerable
- Defined in:
- lib/cvelist/range_dir.rb
Constant Summary collapse
- GLOB =
Dir.glob
pattern for all CVE.json
files. 'CVE-[0-9][0-9][0-9][0-9]-*.json'
Instance Attribute Summary collapse
- #path ⇒ String readonly
- #range ⇒ String readonly
Instance Method Summary collapse
-
#[](cve_id) ⇒ CVE?
Loads a CVE.
-
#each {|cve| ... } ⇒ Enumerator
Enumerates over the CVEs in the range directory.
-
#each_malformed {|malformed| ... } ⇒ Enumerator
Enumerates over the malformed CVEs within the range directory.
-
#files ⇒ Array<String>
The JSON files within the range directory.
-
#has_cve?(cve_id) ⇒ Boolean
Determines whether the range directory contains the given CVE ID.
-
#initialize(path) ⇒ RangeDir
constructor
Initializes the range directory.
Methods inherited from Directory
#directory?, #file?, #glob, #join, #to_s
Constructor Details
#initialize(path) ⇒ RangeDir
Initializes the range directory.
25 26 27 28 29 |
# File 'lib/cvelist/range_dir.rb', line 25 def initialize(path) super(path) @range = File.basename(@path) end |
Instance Attribute Details
#path ⇒ String (readonly)
14 15 16 |
# File 'lib/cvelist/range_dir.rb', line 14 def path @path end |
#range ⇒ String (readonly)
17 18 19 |
# File 'lib/cvelist/range_dir.rb', line 17 def range @range end |
Instance Method Details
#[](cve_id) ⇒ CVE?
Loads a CVE.
53 54 55 56 57 58 59 60 |
# File 'lib/cvelist/range_dir.rb', line 53 def [](cve_id) cve_file = "#{cve_id}.json" cve_path = join(cve_file) if File.file?(cve_path) CVE.load(cve_path) end end |
#each {|cve| ... } ⇒ Enumerator
Enumerates over the CVEs in the range directory.
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cvelist/range_dir.rb', line 86 def each return enum_for(__method__) unless block_given? files.each do |cve_path| begin yield CVE.load(cve_path) rescue InvalidJSON end end end |
#each_malformed {|malformed| ... } ⇒ Enumerator
Enumerates over the malformed CVEs within the range directory.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/cvelist/range_dir.rb', line 108 def each_malformed return enum_for(__method__) unless block_given? files.each do |cve_path| begin CVE.load(cve_path) rescue InvalidJSON => error yield MalformedCVE.new(cve_path,error) end end end |
#files ⇒ Array<String>
The JSON files within the range directory.
70 71 72 |
# File 'lib/cvelist/range_dir.rb', line 70 def files glob(GLOB).sort end |
#has_cve?(cve_id) ⇒ Boolean
Determines whether the range directory contains the given CVE ID.
39 40 41 |
# File 'lib/cvelist/range_dir.rb', line 39 def has_cve?(cve_id) file?("#{cve_id}.json") end |