Class: CVEList::YearDir
- Includes:
- Enumerable
- Defined in:
- lib/cvelist/year_dir.rb
Constant Summary collapse
- GLOB =
Dir.glob
pattern forNxxx
range directories. '*xxx'
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
Path to the year directory.
-
#year ⇒ Integer
readonly
The year of the directory.
Instance Method Summary collapse
-
#[](cve_id) ⇒ CVE?
Loads a CVE.
-
#directories ⇒ Array<String>
The
xxx
number ranges within the directory. -
#each {|cve| ... } ⇒ Enumerator
Enumerates over each CVE, in each range directory, within the year directory.
-
#each_malformed {|malformed_cve| ... } ⇒ Enumerator
Enumerates over every malformed CVE within the year directories.
-
#has_cve?(cve_id) ⇒ Boolean
Determines whether a CVE exists with the given ID, within any of the range directories, within the year directory.
-
#has_range?(xxx_range) ⇒ Boolean
Determines if the year directory contains the given range directory.
-
#initialize(path) ⇒ YearDir
constructor
Initializes the year dir.
-
#range(xxx_range) ⇒ RangeDir
(also: #/)
Access a range directory within the year directory.
-
#ranges(&block) ⇒ Enumerator
The range directories within the year directory.
Methods inherited from Directory
#directory?, #file?, #glob, #join, #to_s
Constructor Details
#initialize(path) ⇒ YearDir
Initializes the year dir.
28 29 30 31 32 |
# File 'lib/cvelist/year_dir.rb', line 28 def initialize(path) super(path) @year = File.basename(@path).to_i end |
Instance Attribute Details
#path ⇒ String (readonly)
Path to the year directory.
15 16 17 |
# File 'lib/cvelist/year_dir.rb', line 15 def path @path end |
#year ⇒ Integer (readonly)
The year of the directory.
20 21 22 |
# File 'lib/cvelist/year_dir.rb', line 20 def year @year end |
Instance Method Details
#[](cve_id) ⇒ CVE?
Loads a CVE.
160 161 162 163 164 165 166 |
# File 'lib/cvelist/year_dir.rb', line 160 def [](cve_id) xxx_range = cve_to_xxx_range(cve_id) if has_range?(xxx_range) range(xxx_range)[cve_id] end end |
#directories ⇒ Array<String>
The xxx
number ranges within the directory.
78 79 80 |
# File 'lib/cvelist/year_dir.rb', line 78 def directories glob(GLOB).sort end |
#each {|cve| ... } ⇒ Enumerator
Enumerates over each CVE, in each range directory, within the year directory.
105 106 107 108 109 110 111 |
# File 'lib/cvelist/year_dir.rb', line 105 def each(&block) return enum_for(__method__) unless block_given? ranges.each do |range_dir| range_dir.each(&block) end end |
#each_malformed {|malformed_cve| ... } ⇒ Enumerator
Enumerates over every malformed CVE within the year directories.
126 127 128 129 130 131 132 |
# File 'lib/cvelist/year_dir.rb', line 126 def each_malformed(&block) return enum_for(__method__) unless block_given? ranges.each do |range_dir| range_dir.each_malformed(&block) end end |
#has_cve?(cve_id) ⇒ Boolean
Determines whether a CVE exists with the given ID, within any of the range directories, within the year directory.
144 145 146 147 148 |
# File 'lib/cvelist/year_dir.rb', line 144 def has_cve?(cve_id) xxx_range = cve_to_xxx_range(cve_id) has_range?(xxx_range) && range(xxx_range).has_cve?(cve_id) end |
#has_range?(xxx_range) ⇒ Boolean
Determines if the year directory contains the given range directory.
42 43 44 |
# File 'lib/cvelist/year_dir.rb', line 42 def has_range?(xxx_range) directory?(xxx_range) end |
#range(xxx_range) ⇒ RangeDir Also known as: /
Access a range directory within the year directory.
58 59 60 61 62 63 64 65 66 |
# File 'lib/cvelist/year_dir.rb', line 58 def range(xxx_range) range_dir_path = join(xxx_range) unless File.directory?(range_dir_path) raise(RangeDirNotFound,"#{xxx_range.inspect} not found within #{@path.inspect}") end return RangeDir.new(range_dir_path) end |