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.

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ PyString

Returns a new instance of PyString.



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

def initialize(string)
  @string = string
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



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

def file
  @file
end

Class Method Details

.default_arg_nameObject



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

def self.default_arg_name
  "string"
end

.parse(text) ⇒ Object



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

def self.parse(text)
  builder = Builder.new
  lexer = Gherkin::I18nLexer.new(builder)
  lexer.scan(text)
  new(builder.string)
end

Instance Method Details

#accept(visitor) ⇒ Object



56
57
58
59
# File 'lib/cucumber/ast/py_string.rb', line 56

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

#arguments_replaced(arguments) ⇒ Object

:nodoc:



61
62
63
64
65
66
67
68
# File 'lib/cucumber/ast/py_string.rb', line 61

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

#has_text?(text) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/cucumber/ast/py_string.rb', line 70

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

#to_sexpObject

For testing only



75
76
77
# File 'lib/cucumber/ast/py_string.rb', line 75

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

#to_step_definition_argObject



52
53
54
# File 'lib/cucumber/ast/py_string.rb', line 52

def to_step_definition_arg
  @string
end