Sha256: 83225f6d21e36aa27bff4296cdc00808ec3fa7c3cf9c5f4deef8f42bfdeb8af0
Contents?: true
Size: 1.51 KB
Versions: 3
Compression:
Stored size: 1.51 KB
Contents
module CucumberAnalytics # A class modeling a Cucumber .feature file. class FeatureFile include Containing # The Feature objects contained by the FeatureFile attr_accessor :features # The parent object that contains *self* attr_accessor :parent_element # 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
3 entries across 3 versions & 1 rubygems