Method: Asciidoctor::AbstractNode#attr

Defined in:
lib/asciidoctor/abstract_node.rb

#attr(name, default_value = nil, fallback_name = nil) ⇒ Object

Get the value of the specified attribute. If the attribute is not found on this node, fallback_name is set, and this node is not the Document node, get the value of the specified attribute from the Document node.

Look for the specified attribute in the attributes on this node and return the value of the attribute, if found. Otherwise, if fallback_name is set (default: same as name) and this node is not the Document node, look for that attribute on the Document node and return its value, if found. Otherwise, return the default value (default: nil).

Parameters:

  • name

    The String or Symbol name of the attribute to resolve.

  • default_value (defaults to: nil)

    The Object value to return if the attribute is not found (default: nil).

  • fallback_name (defaults to: nil)

    The String or Symbol of the attribute to resolve on the Document if the attribute is not found on this node (default: same as name).

Returns:

  • (Object)

    Returns the Object value (typically a String) of the attribute or default_value if the attribute is not found.



88
89
90
# File 'lib/asciidoctor/abstract_node.rb', line 88

def attr name, default_value = nil, fallback_name = nil
  @attributes[name.to_s] || (fallback_name && @parent && @document.attributes[(fallback_name == true ? name : fallback_name).to_s] || default_value)
end