Sha256: c14de74ae1a34aee14ff8e5a5ae213567d0303c3e23b937a4c8a70461f5577ef

Contents?: true

Size: 837 Bytes

Versions: 4

Compression:

Stored size: 837 Bytes

Contents

module Apropos
  # ExtensionParser manages registered variant parsers and provides a base
  # class which new parsers subclass. Parsers are initialized with a pattern
  # (String or Regexp) and a block that is called to generate ClassList or
  # MediaQuery objects from the provided match data.
  class ExtensionParser
    @parsers = {}

    def self.parsers
      @parsers
    end

    def self.add_parser(extension, &block)
      @parsers[extension] = new(extension, &block)
    end

    def self.each_parser(&block)
      parsers.values.each(&block)
    end

    attr_reader :pattern

    def initialize(pattern, &block)
      @pattern = pattern
      @match_block = block
    end

    def match(extension)
      matchdata = pattern.match(extension)
      if matchdata
        @match_block.call(matchdata)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apropos-0.1.3 lib/apropos/extension_parser.rb
apropos-0.1.2 lib/apropos/extension_parser.rb
apropos-0.1.1 lib/apropos/extension_parser.rb
apropos-0.1.0 lib/apropos/extension_parser.rb