Sha256: f9aea8f68b86a3386ed84dd6de200eda05db8ba05626a41d28526b0ff4ce5369

Contents?: true

Size: 843 Bytes

Versions: 3

Compression:

Stored size: 843 Bytes

Contents

require 'turnip/node/base'

module Turnip
  module Node
    #
    # @note Location metadata generated by Gherkin
    #
    #     {
    #       type: :Tag,
    #       location: { line: 10, column: 3 },
    #       name: '@tag'
    #     }
    #
    class Tag < Base
      def name
        @name ||= @raw[:name].gsub(/^@/, '')
      end
    end

    module HasTags
      #
      # @return [Array] Array of Tag
      #
      def tags
        @tags ||= @raw.fetch(:tags, []).map do |tag|
          Tag.new(tag)
        end
      end

      #
      # @return [Array] Array of tag name
      #
      def tag_names
        tags.map(&:name)
      end

      #
      # Convert for hash to be used in RSpec
      #
      # @return  [Hash]
      #
      def metadata_hash
        Hash[tags.map { |t| [t.name.to_sym, true] }]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
turnip-4.3.0 lib/turnip/node/tag.rb
turnip-4.2.0 lib/turnip/node/tag.rb
turnip-4.1.0 lib/turnip/node/tag.rb