class CVEList::YearDir

Constants

GLOB

`Dir.glob` pattern for `Nxxx` range directories.

Attributes

path[R]

Path to the year directory.

@return [String]

year[R]

The year of the directory.

@return [Integer]

Public Class Methods

new(path) click to toggle source

Initializes the year dir.

@param [String] path

The path to the year directory.
Calls superclass method CVEList::Directory::new
# File lib/cvelist/year_dir.rb, line 28
def initialize(path)
  super(path)

  @year = File.basename(@path).to_i
end

Public Instance Methods

/(xxx_range)
Alias for: range
[](cve_id) click to toggle source

Loads a CVE.

@param [String] cve_id

The CVE ID.

@return [CVE, nil]

The loaded CVE or `nil` if the accompaning range directory for the CVE
could not be found.
# 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() click to toggle source

The `xxx` number ranges within the directory.

@return [Array<String>]

# File lib/cvelist/year_dir.rb, line 78
def directories
  glob(GLOB).sort
end
each(&block) click to toggle source

Enumerates over each CVE, in each range directory, within the year directory.

@yield [cve]

The given block will be passed each CVE in the year dir.

@yieldparam [CVE] cve

A CVE within one of the range directories.

@return [Enumerator]

If no block is given, an Enumerator will be returned.
# 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(&block) click to toggle source

Enumerates over every malformed CVE within the year directories.

@yield [malformed_cve]

The given block will be passed each malformed CVE from within the
year directory.

@yieldparam [MalformedCVE] malformed_cve

A malformed CVE from within the year directory.

@return [Enumerator]

If no block is given, an Enumerator will be returned.
# 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) click to toggle source

Determines whether a CVE exists with the given ID, within any of the range directories, within the year directory.

@param [String] cve_id

The given CVE ID.

@return [Boolean]

Specifies whether the CVE exists.
# 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) click to toggle source

Determines if the year directory contains the given range directory.

@param [String] xxx_range

The given range directory ending in `xxx`.

@return [Boolean]

# File lib/cvelist/year_dir.rb, line 42
def has_range?(xxx_range)
  directory?(xxx_range)
end
range(xxx_range) click to toggle source

Access a range directory within the year directory.

@param [String] xxx_range

The "xxx" range.

@return [RangeDir]

The range directory.

@raise [RangeDirNotFound]

Could not find the given range directory within the year directory.
# 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
Also aliased as: /
ranges(&block) click to toggle source

The range directories within the year directory.

@return [Enumerator]

If no block is given, an Enumerator will be returned.
# File lib/cvelist/year_dir.rb, line 88
def ranges(&block)
  directories.map { |dir| RangeDir.new(dir) }
end

Private Instance Methods

cve_to_xxx_range(cve_id) click to toggle source
# File lib/cvelist/year_dir.rb, line 170
def cve_to_xxx_range(cve_id)
  cve_number = cve_id[cve_id.rindex('-')+1 ..]
  cve_number[-3,3] = 'xxx'

  return cve_number
end