Class: Cucumber::Ast::PyString
Overview
Represents an inline argument in a step. Example:
Given the
"""
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.
Class Method Summary collapse
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
-
#arguments_replaced(arguments) ⇒ Object
:nodoc:.
-
#initialize(start_line, end_line, string, quotes_indent) ⇒ PyString
constructor
A new instance of PyString.
- #matches_lines?(lines) ⇒ Boolean
- #status=(status) ⇒ Object
- #to_s ⇒ Object
-
#to_sexp ⇒ Object
For testing only.
Constructor Details
#initialize(start_line, end_line, string, quotes_indent) ⇒ PyString
Returns a new instance of PyString.
25 26 27 28 29 |
# File 'lib/cucumber/ast/py_string.rb', line 25 def initialize(start_line, end_line, string, quotes_indent) @start_line, @end_line = start_line, end_line @string, @quotes_indent = string.gsub(/\\"/, '"'), quotes_indent @status = :passed end |
Class Method Details
.default_arg_name ⇒ Object
21 22 23 |
# File 'lib/cucumber/ast/py_string.rb', line 21 def self.default_arg_name "string" end |
Instance Method Details
#accept(visitor) ⇒ Object
43 44 45 |
# File 'lib/cucumber/ast/py_string.rb', line 43 def accept(visitor) visitor.visit_py_string(to_s, @status) end |
#arguments_replaced(arguments) ⇒ Object
:nodoc:
47 48 49 50 51 52 53 54 |
# File 'lib/cucumber/ast/py_string.rb', line 47 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 |
#matches_lines?(lines) ⇒ Boolean
39 40 41 |
# File 'lib/cucumber/ast/py_string.rb', line 39 def matches_lines?(lines) lines.detect{|l| l >= @start_line && l <= @end_line} end |
#status=(status) ⇒ Object
31 32 33 |
# File 'lib/cucumber/ast/py_string.rb', line 31 def status=(status) @status = status end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/cucumber/ast/py_string.rb', line 35 def to_s @string.indent(-@quotes_indent) end |
#to_sexp ⇒ Object
For testing only
57 58 59 |
# File 'lib/cucumber/ast/py_string.rb', line 57 def to_sexp #:nodoc: [:py_string, to_s] end |