Class: CukeModeler::Directory

Inherits:
Object
  • Object
show all
Includes:
Containing, Nested
Defined in:
lib/cuke_modeler/directory.rb

Overview

A class modeling a directory containing .feature files.

Instance Attribute Summary collapse

Attributes included from Nested

#parent_element

Instance Method Summary collapse

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(directory_parsed = nil) ⇒ Directory

Creates a new Directory object and, if directory_parsed is provided, populates the object.



23
24
25
26
27
28
29
30
31
32
# File 'lib/cuke_modeler/directory.rb', line 23

def initialize(directory_parsed = nil)
  @path = directory_parsed
  @feature_files = []
  @directories = []

  if directory_parsed
    raise(ArgumentError, "Unknown directory: #{directory_parsed.inspect}") unless File.exists?(directory_parsed)
    build_directory
  end
end

Instance Attribute Details

#directoriesObject

The Directory objects contained by the Directory



15
16
17
# File 'lib/cuke_modeler/directory.rb', line 15

def directories
  @directories
end

#feature_filesObject

The FeatureFile objects contained by the Directory



12
13
14
# File 'lib/cuke_modeler/directory.rb', line 12

def feature_files
  @feature_files
end

#pathObject

The file path of the Directory



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

def path
  @path
end

Instance Method Details

#containsObject

Returns the immediate child elements of the directory (i.e. its Directory and FeatureFile objects).



51
52
53
# File 'lib/cuke_modeler/directory.rb', line 51

def contains
  @feature_files + @directories
end

#directory_countObject

Returns the number of sub-directories contained in the directory.



40
41
42
# File 'lib/cuke_modeler/directory.rb', line 40

def directory_count
  @directories.count
end

#feature_file_countObject

Returns the number of features files contained in the directory.



45
46
47
# File 'lib/cuke_modeler/directory.rb', line 45

def feature_file_count
  @feature_files.count
end

#nameObject

Returns the name of the directory.



35
36
37
# File 'lib/cuke_modeler/directory.rb', line 35

def name
  File.basename(@path.gsub('\\', '/')) if @path
end

#to_sObject

Returns the path of the directory.



56
57
58
# File 'lib/cuke_modeler/directory.rb', line 56

def to_s
  path.to_s
end