class CucumberAnalytics::DocString
A class modeling the Doc String of a Step
.
Attributes
content_type[RW]
The content type associated with the doc string
contents[RW]
Deprecated
The contents of the doc string
contents_text[RW]
The contents of the doc string
Public Class Methods
new(source = nil)
click to toggle source
Creates a new DocString
object and, if source is provided, populates the object.
# File lib/cucumber_analytics/doc_string.rb, line 25 def initialize(source = nil) @contents = [] @contents_text = '' parsed_doc_string = process_source(source) build_doc_string(parsed_doc_string) if parsed_doc_string end
Public Instance Methods
to_s()
click to toggle source
Returns a gherkin representation of the doc string.
# File lib/cucumber_analytics/doc_string.rb, line 35 def to_s text = "\"\"\"#{content_type_output_string}\n" text << contents_output_string text << '"""' end
Private Instance Methods
build_doc_string(doc_string)
click to toggle source
# File lib/cucumber_analytics/doc_string.rb, line 63 def build_doc_string(doc_string) populate_content_type(doc_string) populate_contents(doc_string) populate_raw_element(doc_string) end
content_type_output_string()
click to toggle source
# File lib/cucumber_analytics/doc_string.rb, line 78 def content_type_output_string content_type ? " #{content_type}" : '' end
contents_output_string()
click to toggle source
# File lib/cucumber_analytics/doc_string.rb, line 82 def contents_output_string contents_text.empty? ? '' : contents_text.gsub('"""', '\"\"\"') + "\n" end
parse_doc_string(source_text)
click to toggle source
# File lib/cucumber_analytics/doc_string.rb, line 54 def parse_doc_string(source_text) base_file_string = "Feature:\nScenario:\n* step\n" source_text = base_file_string + source_text parsed_file = Parsing::parse_text(source_text) parsed_file.first['elements'].first['steps'].first['doc_string'] end
populate_content_type(doc_string)
click to toggle source
# File lib/cucumber_analytics/doc_string.rb, line 69 def populate_content_type(doc_string) @content_type = doc_string['content_type'] == "" ? nil : doc_string['content_type'] end
populate_contents(doc_string)
click to toggle source
# File lib/cucumber_analytics/doc_string.rb, line 73 def populate_contents(doc_string) @contents = doc_string['value'].split($/, -1) @contents_text = doc_string['value'] end
process_source(source)
click to toggle source
# File lib/cucumber_analytics/doc_string.rb, line 45 def process_source(source) case when source.is_a?(String) parse_doc_string(source) else source end end