class CucumberAnalytics::FeatureFile

A class modeling a Cucumber .feature file.

Attributes

features[RW]

The Feature objects contained by the FeatureFile

Public Class Methods

new(file = nil) click to toggle source

Creates a new FeatureFile object and, if file_parsed is provided, populates the object.

# File lib/cucumber_analytics/feature_file.rb, line 17
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

Public Instance Methods

contains() click to toggle source

Returns the immediate child elements of the file(i.e. its Feature object).

# File lib/cucumber_analytics/feature_file.rb, line 41
def contains
  @features
end
feature() click to toggle source

Returns the Feature object contained by the FeatureFile.

# File lib/cucumber_analytics/feature_file.rb, line 51
def feature
  @features.first
end
feature_count() click to toggle source

Returns the number of features contained in the file.

# File lib/cucumber_analytics/feature_file.rb, line 46
def feature_count
  @features.count
end
name() click to toggle source

Returns the name of the file.

# File lib/cucumber_analytics/feature_file.rb, line 31
def name
  File.basename(@file.gsub('\\', '/'))
end
path() click to toggle source

Returns the path of the file.

# File lib/cucumber_analytics/feature_file.rb, line 36
def path
  @file
end
to_s() click to toggle source

Returns the path of the feature file.

# File lib/cucumber_analytics/feature_file.rb, line 56
def to_s
  path.to_s
end

Private Instance Methods

build_file(parsed_file) click to toggle source
# File lib/cucumber_analytics/feature_file.rb, line 70
def build_file(parsed_file)
  unless parsed_file.empty?
    @features << build_child_element(Feature, parsed_file.first)
  end
end
parse_file(file_to_parse) click to toggle source
# File lib/cucumber_analytics/feature_file.rb, line 64
def parse_file(file_to_parse)
  source_text = IO.read(file_to_parse)

  Parsing::parse_text(source_text)
end