Class: Cukehead::FeatureNode
- Inherits:
-
Object
- Object
- Cukehead::FeatureNode
- Defined in:
- lib/cukehead/feature_node.rb
Overview
Responsible for extracting the attributes of a feature from a XML node (REXML::Element) and providing those attributes as text in Cucumber feature file format.
Instance Method Summary collapse
-
#filename ⇒ Object
Returns a string that is either the file name given explititly in the mind map or a file name constructed from the feature title.
-
#filename_from(text) ⇒ Object
Returns the file name extracted from the given text where the format is ‘[file: filename.feature]’ or ‘[file: “filename.feature”]’.
-
#initialize(node) ⇒ FeatureNode
constructor
Extracts the attributes of a feature from a mind map node.
-
#title_as_filename ⇒ Object
Returns the feature title as a string suitable for use as a file name.
-
#to_text ⇒ Object
Returns a string containing the attributes of this feature as text formatted for output to a Cucumber feature file.
Constructor Details
#initialize(node) ⇒ FeatureNode
Extracts the attributes of a feature from a mind map node.
Parameters
node
- REXML::Element
17 18 19 20 21 22 23 24 25 |
# File 'lib/cukehead/feature_node.rb', line 17 def initialize(node) @feature_filename = "" @description = [] @backgrounds = [] @scenarios = [] @tags = FeatureNodeTags.new @title = node.attributes["TEXT"] from_mm_node node end |
Instance Method Details
#filename ⇒ Object
Returns a string that is either the file name given explititly in the mind map or a file name constructed from the feature title.
41 42 43 44 45 46 47 |
# File 'lib/cukehead/feature_node.rb', line 41 def filename if @feature_filename.empty? title_as_filename else @feature_filename end end |
#filename_from(text) ⇒ Object
Returns the file name extracted from the given text where the format is ‘[file: filename.feature]’ or ‘[file: “filename.feature”]’.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cukehead/feature_node.rb', line 53 def filename_from(text) a = text.index ':' if a.nil? then return "" end b = text.index ']' if b.nil? then return "" end a += 1 if a > 5 and b > a text.slice(a, b-a).delete('"').strip else "" end end |
#title_as_filename ⇒ Object
Returns the feature title as a string suitable for use as a file name.
30 31 32 33 34 35 |
# File 'lib/cukehead/feature_node.rb', line 30 def title_as_filename result = '' t = @title.strip.gsub(/^feature:/i, ' ').strip t.downcase.gsub(/\ /, '_').scan(/[_0-9a-z]/) {|c| result << c } result + '.feature' end |
#to_text ⇒ Object
Returns a string containing the attributes of this feature as text formatted for output to a Cucumber feature file.
70 71 72 73 74 75 76 77 78 |
# File 'lib/cukehead/feature_node.rb', line 70 def to_text text = @tags.to_text('') + @title + "\n" pad = " " @description.each {|line| text += pad + line + "\n"} text += "\n" @backgrounds.each {|background| text += background.to_text(pad) + "\n"} @scenarios.each {|scenario| text += scenario.to_text(pad) + "\n"} text end |