Class: Apropos::ExtensionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/apropos/extension_parser.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, &block) ⇒ ExtensionParser

Returns a new instance of ExtensionParser.



23
24
25
26
# File 'lib/apropos/extension_parser.rb', line 23

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

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



21
22
23
# File 'lib/apropos/extension_parser.rb', line 21

def pattern
  @pattern
end

Class Method Details

.add_parser(extension, &block) ⇒ Object



13
14
15
# File 'lib/apropos/extension_parser.rb', line 13

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

.each_parser(&block) ⇒ Object



17
18
19
# File 'lib/apropos/extension_parser.rb', line 17

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

.parsersObject



9
10
11
# File 'lib/apropos/extension_parser.rb', line 9

def self.parsers
  @parsers
end

Instance Method Details

#match(extension) ⇒ Object



28
29
30
31
32
33
# File 'lib/apropos/extension_parser.rb', line 28

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