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

Version Path
rubyfocus-0.5.16 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.15 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.14 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.13 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.12 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.11 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.9 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.6 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.5 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.4 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.3 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.2 lib/rubyfocus/includes/parser.rb
rubyfocus-0.5.1 lib/rubyfocus/includes/parser.rb
rubyfocus-0.4.0 lib/rubyfocus/includes/parser.rb
rubyfocus-0.3.1 lib/rubyfocus/includes/parser.rb
rubyfocus-0.3.0 lib/rubyfocus/includes/parser.rb