Module: Rubyfocus::Parser

Included in:
Context, Folder, Project, Setting, Task
Defined in:
lib/rubyfocus/includes/parser.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



24
25
26
27
# File 'lib/rubyfocus/includes/parser.rb', line 24

def self.included(mod)
	@subclasses << mod
	mod.extend ClassMethods
end

.parse(document, node) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rubyfocus/includes/parser.rb', line 5

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