Sha256: ad2c243ac7f33570b23d04f8dc02fb42949b2c6d05fa55bf53e822021ce87a36

Contents?: true

Size: 597 Bytes

Versions: 4

Compression:

Stored size: 597 Bytes

Contents

require 'commonmarker/node'
require 'grokdown'

module Grokdown
  module Matching
    class << self
      @@knowns = []

      def extended(base)
        @@knowns.push(base)
      end

      def matches?(node)
        @@knowns.any? {|i| i.matches?(node)}
      end

      def for(node)
        @@knowns.find {|i| i.matches?(node)}
      end

      alias_method :===, :matches?
    end

    def match(&block)
      @matcher = block
    end

    def matches?(node)
      node.is_a?(self) || (node.is_a?(CommonMarker::Node) && @matcher.call(node))
    end

    alias_method :===, :matches?
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
grokdown-0.2.1 lib/grokdown/matching.rb
grokdown-0.2.0 lib/grokdown/matching.rb
grokdown-0.1.1 lib/grokdown/matching.rb
grokdown-0.1.0 lib/grokdown/matching.rb