Class: Kitchen::ElementFactory
Overview
Builds Elements from Nokogiri Nodes
Constant Summary collapse
- ELEMENT_CLASSES =
ElementBase.descendants
Class Method Summary collapse
-
.build_from_node(node:, document:, element_class: nil, default_short_type: nil, detect_element_class: false) ⇒ ElementBase
Builds a new concrete subclass of ElementBase for the provided node.
- .find_element_class(node, config) ⇒ Object
Class Method Details
.build_from_node(node:, document:, element_class: nil, default_short_type: nil, detect_element_class: false) ⇒ ElementBase
Builds a new concrete subclass of ElementBase for the provided node.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kitchen/element_factory.rb', line 23 def self.build_from_node(node:, document:, element_class: nil, default_short_type: nil, detect_element_class: false) element_class ||= detect_element_class ? find_element_class(node, document.config) : Element if element_class == Element element_class.new(node: node, document: document, short_type: default_short_type) else element_class.new(node: node, document: document) end end |
.find_element_class(node, config) ⇒ Object
40 41 42 43 44 |
# File 'lib/kitchen/element_factory.rb', line 40 def self.find_element_class(node, config) ELEMENT_CLASSES.find do |klass| klass.is_the_element_class_for?(node, config: config) end || Element end |