Class: Cukedep::GherkinFacade
- Inherits:
-
Object
- Object
- Cukedep::GherkinFacade
- Defined in:
- lib/cukedep/gherkin-facade.rb
Overview
Facade design pattern: A facade is an object that provides a simplified interface to a larger body of code. Here the GherkinFacade class provides basic parsing service.
Instance Attribute Summary collapse
-
#external_encoding ⇒ Object
readonly
(External) encoding of the feature files.
-
#verbose ⇒ Object
readonly
Indicate whether the parsing must be verbose or silent.
Instance Method Summary collapse
-
#initialize(isVerbose, anExternalEncoding) ⇒ GherkinFacade
constructor
A new instance of GherkinFacade.
-
#parse_features(aListener, file_patterns) ⇒ Object
Parse feature files from the work directory that match one of the given file name patterns.
- #parse_raw_feature(raw_feature, file_name, listener) ⇒ Object
Constructor Details
#initialize(isVerbose, anExternalEncoding) ⇒ GherkinFacade
Returns a new instance of GherkinFacade.
18 19 20 21 |
# File 'lib/cukedep/gherkin-facade.rb', line 18 def initialize(isVerbose, anExternalEncoding) @verbose = isVerbose @external_encoding = anExternalEncoding end |
Instance Attribute Details
#external_encoding ⇒ Object (readonly)
(External) encoding of the feature files. It is a string that represents the name of an encoding as expected by the mode argument of the IO#new method
16 17 18 |
# File 'lib/cukedep/gherkin-facade.rb', line 16 def external_encoding @external_encoding end |
#verbose ⇒ Object (readonly)
Indicate whether the parsing must be verbose or silent
11 12 13 |
# File 'lib/cukedep/gherkin-facade.rb', line 11 def verbose @verbose end |
Instance Method Details
#parse_features(aListener, file_patterns) ⇒ Object
Parse feature files from the work directory that match one of the given file name patterns. Parse events are sent to the passed listener object.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cukedep/gherkin-facade.rb', line 26 def parse_features(aListener, file_patterns) # Create a Gherkin parser parser = Gherkin::Parser.new puts "\nParsing:" if verbose # List all .feature files in work directory that match the pattern filenames = [] file_patterns.each { |patt| filenames.concat(Dir.glob(patt)) } # Parse them filenames.each do |fname| puts " #{fname}" if verbose # To prevent encoding issue, open the file # with an explicit external encoding File.open(fname, "r:#{external_encoding}") do |f| raw = parser.parse(f.read) parse_raw_feature(raw[:feature], fname, aListener) if raw[:feature] end end return aListener end |
#parse_raw_feature(raw_feature, file_name, listener) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/cukedep/gherkin-facade.rb', line 48 def parse_raw_feature(raw_feature, file_name, listener) listener.uri(file_name) = raw_feature[:tags] tag_names = .map { |raw_tag| raw_tag[:name] } listener.(tag_names) end |