Class: Cucumber::Ast::PyString

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber/ast/py_string.rb

Overview

Represents an inline argument in a step. Example:

Given the message
  """
  I like
  Cucumber sandwich
  """

The text between the pair of """ is stored inside a PyString, which is yielded to the StepDefinition block as the last argument.

The StepDefinition can then access the String via the #to_s method. In the example above, that would return: "I like\nCucumber sandwich"

Note how the indentation from the source is stripped away.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_line, end_line, string, quotes_indent) ⇒ PyString

Returns a new instance of PyString.



26
27
28
29
# File 'lib/cucumber/ast/py_string.rb', line 26

def initialize(start_line, end_line, string, quotes_indent)
  @start_line, @end_line = start_line, end_line
  @string, @quotes_indent = string.gsub(/\\"/, '"'), quotes_indent
end

Instance Attribute Details

#fileObject

:nodoc:



20
21
22
# File 'lib/cucumber/ast/py_string.rb', line 20

def file
  @file
end

Class Method Details

.default_arg_nameObject



22
23
24
# File 'lib/cucumber/ast/py_string.rb', line 22

def self.default_arg_name
  "string"
end

Instance Method Details

#accept(visitor) ⇒ Object



35
36
37
38
# File 'lib/cucumber/ast/py_string.rb', line 35

def accept(visitor)
  return if Cucumber.wants_to_quit
  visitor.visit_py_string(to_s)
end

#arguments_replaced(arguments) ⇒ Object

:nodoc:



40
41
42
43
44
45
46
47
# File 'lib/cucumber/ast/py_string.rb', line 40

def arguments_replaced(arguments) #:nodoc:
  string = @string
  arguments.each do |name, value|
    value ||= ''
    string = string.gsub(name, value)
  end
  PyString.new(@start_line, @end_line, string, @quotes_indent)
end

#has_text?(text) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/cucumber/ast/py_string.rb', line 49

def has_text?(text)
  @string.index(text)
end

#to_sObject



31
32
33
# File 'lib/cucumber/ast/py_string.rb', line 31

def to_s
  @string.indent(-@quotes_indent)
end

#to_sexpObject

For testing only



54
55
56
# File 'lib/cucumber/ast/py_string.rb', line 54

def to_sexp #:nodoc:
  [:py_string, to_s]
end