Sha256: 342fd3337a0314c869b6714f2a11e381f485e6f11b93bb659ff3466599e3a310

Contents?: true

Size: 1.45 KB

Versions: 4

Compression:

Stored size: 1.45 KB

Contents

module CucumberAnalytics

  # A class modeling a Cucumber .feature file.

  class FeatureFile

    include Containing
    include Nested


    # The Feature objects contained by the FeatureFile
    attr_accessor :features


    # Creates a new FeatureFile object and, if *file_parsed* is provided,
    # populates the object.
    def initialize(file = nil)
      @file = file
      @features = []

      if file
        raise(ArgumentError, "Unknown file: #{file.inspect}") unless File.exists?(file)

        parsed_file = parse_file(file)

        build_file(parsed_file)
      end
    end

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

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

    # Returns the immediate child elements of the file(i.e. its Feature object).
    def contains
      @features
    end

    # Returns the number of features contained in the file.
    def feature_count
      @features.count
    end

    # Returns the Feature object contained by the FeatureFile.
    def feature
      @features.first
    end


    private


    def parse_file(file_to_parse)
      source_text = IO.read(file_to_parse)

      Parsing::parse_text(source_text)
    end

    def build_file(parsed_file)
      unless parsed_file.empty?
        @features << build_child_element(Feature, parsed_file.first)
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cucumber_analytics-1.4.2 lib/cucumber_analytics/feature_file.rb
cucumber_analytics-1.4.1 lib/cucumber_analytics/feature_file.rb
cucumber_analytics-1.4.0 lib/cucumber_analytics/feature_file.rb
cucumber_analytics-1.3.0 lib/cucumber_analytics/feature_file.rb