class CukeModeler::DocString

A class modeling a step's doc string.

Attributes

content[RW]

The content of the doc string

content_type[RW]

The content type associated with the doc string

Public Class Methods

new(source_text = nil) click to toggle source

Creates a new DocString object and, if source_text is provided, populates the object.

Calls superclass method
# File lib/cuke_modeler/models/doc_string.rb, line 20
def initialize(source_text = nil)
  super(source_text)

  return unless source_text

  parsed_doc_string_data = parse_source(source_text)
  populate_docstring(self, parsed_doc_string_data)
end

Public Instance Methods

to_s() click to toggle source

Returns a string representation of this model. For a doc string model, this will be Gherkin text that is equivalent to the doc string being modeled.

# File lib/cuke_modeler/models/doc_string.rb, line 31
def to_s
  text = "\"\"\"#{content_type_output_string}\n"
  text << content_output_string
  text << '"""'
end

Private Instance Methods

content_output_string() click to toggle source
# File lib/cuke_modeler/models/doc_string.rb, line 57
def content_output_string
  content.nil? || content.empty? ? '' : content.gsub('"""', '\"\"\"') + "\n"
end
content_type_output_string() click to toggle source
# File lib/cuke_modeler/models/doc_string.rb, line 53
def content_type_output_string
  content_type ? " #{content_type}" : ''
end
parse_source(source_text) click to toggle source
# File lib/cuke_modeler/models/doc_string.rb, line 41
def parse_source(source_text)
  base_file_string = "# language: #{Parsing.dialect}
  #{dialect_feature_keyword}:
                        #{dialect_scenario_keyword}:
                          #{dialect_step_keyword} step\n"
  source_text = base_file_string + source_text

  parsed_file = Parsing.parse_text(source_text, 'cuke_modeler_stand_alone_doc_string.feature')

  parsed_file['feature']['elements'].first['steps'].first['doc_string']
end