Sha256: d93c04a33deafa3c51fb9ea05cff8d385e1e880a4306ccb2cd91312d11a17686

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

module CucumberAnalytics

  # A class modeling a directory containing .feature files.

  class Directory

    include Containing


    # The FeatureFile objects contained by the Directory
    attr_accessor :feature_files

    # The Directory objects contained by the Directory
    attr_accessor :directories

    # The parent object that contains *self*
    attr_accessor :parent_element


    # Creates a new Directory object and, if *directory_parsed* is provided,
    # populates the object.
    def initialize(directory_parsed = nil)
      @directory = directory_parsed

      @feature_files = []
      @directories = []

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

    # Returns the name of the directory.
    def name
      File.basename(@directory.gsub('\\', '/'))
    end

    # Returns the path of the directory.
    def path
      @directory
    end

    # Returns the number of sub-directories contained in the directory.
    def directory_count
      @directories.count
    end

    # Returns the number of features files contained in the directory.
    def feature_file_count
      @feature_files.count
    end

    # Returns the immediate child elements of the directory (i.e. its Directory
    # and FeatureFile objects).
    def contains
      @feature_files + @directories
    end


    private


    def build_directory
      entries = Dir.entries(@directory)
      entries.delete '.'
      entries.delete '..'

      entries.each do |entry|
        entry = "#{@directory}/#{entry}"

        case
          when File.directory?(entry)
            @directories << build_child_element(Directory, entry)
          when entry =~ /\.feature$/
            @feature_files << build_child_element(FeatureFile, entry)
        end
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cucumber_analytics-1.2.0 lib/cucumber_analytics/directory.rb
cucumber_analytics-1.1.1 lib/cucumber_analytics/directory.rb
cucumber_analytics-1.0.0 lib/cucumber_analytics/directory.rb