Sha256: f15b9a89c1a38e73b173120d32b34e33b62882effa113fd5fc860adf5928e25d

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 KB

Contents

module Cucumber
  module Ast
    # Represents an inline argument in a step. Example:
    #
    #   Given the message
    #     """
    #     I like
    #     Cucumber sandwich
    #     """
    #
    # The text between the pair of <tt>"""</tt> 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: <tt>"I like\nCucumber sandwich"</tt>
    #
    # Note how the indentation from the source is stripped away.
    #
    class PyString
      def initialize(start_line, end_line, string, quotes_indent)
        @start_line, @end_line = start_line, end_line
        @string, @quotes_indent = string, quotes_indent
      end

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

      def at_lines?(lines)
        lines.detect{|l| l >= @start_line && l <= @end_line}
      end

      def accept(visitor, status)
        visitor.visit_py_string(to_s, status)
      end
      
      def arguments_replaced(arguments) #:nodoc:
        string = @string
        arguments.each do |name, value|
          string = string.gsub(name, value)
        end
        PyString.new(@start_line, @end_line, string, @quotes_indent)
      end
      
      # For testing only
      def to_sexp #:nodoc:
        [:py_string, to_s]
      end
                
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
aslakhellesoy-cucumber-0.1.16.5 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.1.99.1 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.1.99.10 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.1.99.2 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.1.99.3 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.1.99.5 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.1.99.6 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.1.99.7 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.1.99.8 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.1.99.9 lib/cucumber/ast/py_string.rb