Class: CVEList::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/cvelist/directory.rb

Overview

Represents a directory within the Repository.

Direct Known Subclasses

RangeDir, Repository, YearDir

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Directory

Initializes the directory.

Parameters:

  • path (String)

    The path to the directory.



18
19
20
# File 'lib/cvelist/directory.rb', line 18

def initialize(path)
  @path = File.expand_path(path)
end

Instance Attribute Details

#pathString (readonly)

The path to the directory.

Returns:

  • (String)


10
11
12
# File 'lib/cvelist/directory.rb', line 10

def path
  @path
end

Instance Method Details

#directory?(name) ⇒ Boolean

Determines whether the directory has the given directory.

Parameters:

  • name (String)

Returns:

  • (Boolean)


52
53
54
# File 'lib/cvelist/directory.rb', line 52

def directory?(name)
  File.directory?(join(name))
end

#file?(name) ⇒ Boolean

Determines whether the directory has the givne file.

Parameters:

  • name (String)

Returns:

  • (Boolean)


41
42
43
# File 'lib/cvelist/directory.rb', line 41

def file?(name)
  File.file?(join(name))
end

#glob(pattern) ⇒ Array<String>

Finds all files and directories matching the pattern.

Parameters:

  • pattern (String)

    The glob pattern.

Returns:

  • (Array<String>)

    The matching file and directory paths.



65
66
67
# File 'lib/cvelist/directory.rb', line 65

def glob(pattern)
  Dir[join(pattern)]
end

#join(*names) ⇒ String

Joins the file/directory name(s) with the directory path.

Parameters:

  • names (Array<String>)

    The file/directory name(s).

Returns:

  • (String)


30
31
32
# File 'lib/cvelist/directory.rb', line 30

def join(*names)
  File.join(@path,*names)
end

#to_sString

Converts the directory to a String.

Returns:

  • (String)

    The path to the directory.



75
76
77
# File 'lib/cvelist/directory.rb', line 75

def to_s
  @path
end