Class: Mache::Node Abstract

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/mache/node.rb

Overview

This class is abstract.

The Node class represents a wrapped HTML page, or fragment. It exposes all methods from the Mache DSL, and forwards any Capybara API methods to the #node object.

Direct Known Subclasses

Page

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

included

Constructor Details

#initialize(node:) ⇒ Node

Returns a new instance of Node.

Parameters:

  • node (Capybara::Node)

    a Capybara node object to wrap



20
21
22
# File 'lib/mache/node.rb', line 20

def initialize(node:)
  @node = node
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/mache/node.rb', line 33

def method_missing(name, *args, &block)
  if @node.respond_to?(name)
    @node.send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#nodeCapybara::Node (readonly)

The underlying Capybara node object wrapped by this instance.

Returns:

  • (Capybara::Node)

    a node object



15
16
17
# File 'lib/mache/node.rb', line 15

def node
  @node
end

Instance Method Details

#empty?Boolean

Tests whether the node is empty.

Returns:

  • (Boolean)

    ‘true` if the node is empty, `false` otherwise.



27
28
29
# File 'lib/mache/node.rb', line 27

def empty?
  node.all('*').length.zero?
end