Sha256: ce082169d15c6d085b60ac2ade2feed29f3d8ea1c459d40cf7c7aa130b697d54
Contents?: true
Size: 830 Bytes
Versions: 16
Compression:
Stored size: 830 Bytes
Contents
module Rubyfocus module Parser @subclasses = [] def self.parse(document, node) matching_classes = @subclasses.select{ |klass| klass.matches_node?(node) } # More than one matches? Take the most specific if matching_classes.size > 1 classes_with_subclasses = matching_classes.select{ |c| matching_classes.any?{ |sc| sc < c } } matching_classes = matching_classes - classes_with_subclasses end case matching_classes.size when 0 nil when 1 return matching_classes.first.new(document, node) else raise RuntimeError, "Node #{node.inspect} matches more than one Rubyfocus::Item subclass." end end def self.included(mod) @subclasses << mod mod.extend ClassMethods end module ClassMethods # Filler method def matches_node?(node) false end end end end
Version data entries
16 entries across 16 versions & 1 rubygems