Sha256: 69e838009b55b38301040dcb04e001a3a5701d2d3ea11959fdc4dc2ccc3f7303

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 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
        @argument ||= case
                      when @raw[:doc_string]
                        doc_string(@raw[:doc_string])
                      when @raw[:data_table]
                        data_table(@raw[:data_table])
                      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

5 entries across 5 versions & 1 rubygems

Version Path
turnip-4.3.0 lib/turnip/node/step.rb
turnip-4.2.0 lib/turnip/node/step.rb
turnip-4.1.0 lib/turnip/node/step.rb
turnip-4.0.1 lib/turnip/node/step.rb
turnip-4.0.0 lib/turnip/node/step.rb