Class: CukeModeler::DocString

Inherits:
Model
  • Object
show all
Includes:
Parsed, Parsing, Sourceable
Defined in:
lib/cuke_modeler/models/doc_string.rb

Overview

A class modeling a step’s doc string.

Instance Attribute Summary collapse

Attributes included from Sourceable

#source_column, #source_line

Attributes included from Parsed

#parsing_data

Attributes included from Nested

#parent_model

Instance Method Summary collapse

Methods included from Parsing

dialects, parse_text

Methods inherited from Model

#children

Methods included from Containing

#each, #each_descendant, #each_model

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(source_text = nil) ⇒ DocString

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

Examples:

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

Parameters:

  • source_text (String) (defaults to: nil)

    The Gherkin text that will be used to populate the model

Raises:

  • (ArgumentError)

    If source_text is not a String



28
29
30
# File 'lib/cuke_modeler/models/doc_string.rb', line 28

def initialize(source_text = nil)
  super(source_text)
end

Instance Attribute Details

#contentObject

The content of the doc string



15
16
17
# File 'lib/cuke_modeler/models/doc_string.rb', line 15

def content
  @content
end

#content_typeObject

The content type associated with the doc string



12
13
14
# File 'lib/cuke_modeler/models/doc_string.rb', line 12

def content_type
  @content_type
end

Instance Method Details

#inspect(verbose: false) ⇒ String

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.

Examples:

doc_string.inspect
doc_string.inspect(verbose: true)

Parameters:

  • verbose (Boolean) (defaults to: false)

    Whether or not to return the full details of the object. Defaults to false.

Returns:

  • (String)

    A string representation of this model



58
59
60
61
62
# File 'lib/cuke_modeler/models/doc_string.rb', line 58

def inspect(verbose: false)
  return super(verbose: verbose) if verbose

  "#{super.chop} @content: #{content.inspect}>"
end

#to_sString

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.

Examples:

doc_string.to_s

Returns:

  • (String)

    A string representation of this model



39
40
41
42
43
# 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