Module: Yerba::Node::ClassMethods

Defined in:
lib/yerba/node.rb

Instance Method Summary collapse

Instance Method Details

#coerce_location(location) ⇒ Object



48
49
50
51
52
# File 'lib/yerba/node.rb', line 48

def coerce_location(location)
  return location unless location.is_a?(Hash)

  Location.new(**location.transform_keys(&:to_sym))
end

#from(file_path:, selector:, line: nil, location: nil, **attributes) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/yerba/node.rb', line 39

def from(file_path:, selector:, line: nil, location: nil, **attributes)
  instance = allocate

  instance.send(:init_node, nil, selector, coerce_location(location), nil, file_path, line)
  instance.send(:init_from, **attributes) if instance.respond_to?(:init_from, true)

  instance
end

#from_document(document, selector, location = nil, key = nil, **attributes) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/yerba/node.rb', line 30

def from_document(document, selector, location = nil, key = nil, **attributes)
  instance = allocate

  instance.send(:init_node, document, selector, location, key, nil, nil)
  instance.send(:init_from, **attributes) if instance.respond_to?(:init_from, true)

  instance
end