Sha256: 3971d696cef38377c67e9377cff0503548edf7a8afb8db19556fbfb4d65053d3
Contents?: true
Size: 1.53 KB
Versions: 4
Compression:
Stored size: 1.53 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 # Returns the path of the feature file. def to_s path.to_s 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