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.

@example

DocString.new
DocString.new("\"\"\" some_type\n  foo\n\"\"\"")

@param source_text [String] The Gherkin text that will be used to populate the model @raise [ArgumentError] If source_text is not a String @return [DocString] A new DocString instance

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

Public Instance Methods

inspect(verbose: false) click to toggle source

See ‘Object#inspect`. Returns some basic information about the object, including its class, object ID, and its most meaningful attribute. For a DocString model, this will be the content of the doc string. If verbose is true, provides default Ruby inspection behavior instead.

@example

doc_string.inspect
doc_string.inspect(verbose: true)

@param verbose [Boolean] Whether or not to return the full details of

the object. Defaults to false.

@return [String] A string representation of this model

Calls superclass method
# File lib/cuke_modeler/models/doc_string.rb, line 58
def inspect(verbose: false)
  return super if verbose

  "#{super.chop} @content: #{content.inspect}>"
end
to_s() click to toggle source

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

@example

doc_string.to_s

@return [String] A string representation of this model

# File lib/cuke_modeler/models/doc_string.rb, line 39
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 99
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 95
def content_type_output_string
  content_type ? " #{content_type}" : ''
end
populate_content(parsed_doc_string_data) click to toggle source
# File lib/cuke_modeler/models/doc_string.rb, line 91
def populate_content(parsed_doc_string_data)
  @content = parsed_doc_string_data['value']
end
populate_content_type(parsed_doc_string_data) click to toggle source
# File lib/cuke_modeler/models/doc_string.rb, line 87
def populate_content_type(parsed_doc_string_data)
  @content_type = parsed_doc_string_data['content_type']
end
populate_model(parsed_doc_string_data) click to toggle source
# File lib/cuke_modeler/models/doc_string.rb, line 80
def populate_model(parsed_doc_string_data)
  populate_content_type(parsed_doc_string_data)
  populate_content(parsed_doc_string_data)
  populate_parsing_data(parsed_doc_string_data)
  populate_source_location(parsed_doc_string_data)
end
process_source(source_text) click to toggle source
# File lib/cuke_modeler/models/doc_string.rb, line 68
def process_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