Sha256: ba64c0a0e1563d2435841e99642a89dfea8aa5c645252315c0a61157c0f960c3

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

require 'turnip/node/base'
require 'turnip/table'

module Turnip
  module Node
    #
    # @note Step metadata generated by Gherkin
    #
    #     {
    #       type: :Step,
    #       location: { line: 10, column: 3 },
    #       keyword: 'Step',
    #       text: 'Step description',
    #       argument: {}, # DocString or DataTable
    #     }
    #
    class Step < Base
      def keyword
        @raw[:keyword]
      end

      def text
        @raw[:text]
      end

      #
      # Backward compatibility
      #
      def description
        text
      end

      def argument
        return nil if @raw[:argument].nil?

        @argument ||= case @raw[:argument][:type]
                      when :DocString
                        doc_string(@raw[:argument])
                      when :DataTable
                        data_table(@raw[:argument])
                      end
      end

      def to_s
        "#{keyword}#{text}"
      end

      private

      def doc_string(doc)
        doc[:content]
      end

      def data_table(table)
        rows = table[:rows].map do |row|
          row[:cells].map do |cell|
            cell[:value]
          end
        end
        Turnip::Table.new(rows)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
turnip-3.1.0 lib/turnip/node/step.rb
turnip-3.0.0 lib/turnip/node/step.rb
turnip-3.0.0.pre.beta.5 lib/turnip/node/step.rb
turnip-3.0.0.pre.beta.4 lib/turnip/node/step.rb
turnip-3.0.0.pre.beta.3 lib/turnip/node/step.rb
turnip-3.0.0.pre.beta.2 lib/turnip/node/step.rb