class Paru::PandocFilter::Attr

Attr represents an attribute object for a node. It contains of an id, a list of class names and a list of key-value pairs.

@see hackage.haskell.org/package/pandoc-types-1.17.0.5/docs/Text-Pandoc-Definition.html#t:Attr

@!attribute id

@return [String]

@!attribute classes

@return [Array<String>]

Attributes

classes[RW]
id[RW]

Public Class Methods

new(attributes = []) click to toggle source

Create a new attributes object

@param attributes [Array = []] the attributes as [id, [class names],

[key-value pairs]]
# File lib/paru/filter/attr.rb, line 40
def initialize(attributes = [])
    id, classes, data = attributes
          
    @id = id || ""

    @classes = classes || []
    @classes = [@classes] unless @classes.is_a? Array

    @data = Hash[data] || {}
end

Public Instance Methods

[](key) click to toggle source

Get the value for key in this attributes object

@param key [String] the key to get the value for. Nil if it does not exists

# File lib/paru/filter/attr.rb, line 60
def [](key) 
    if @data.key? key
        @data[key]
    end 
end
each() click to toggle source

For each key-value pair of this attributes object

# File lib/paru/filter/attr.rb, line 52
def each
    @data.each
end
has_class?(name) click to toggle source

Does this attributes object have a class?

@param name [String] the class name to search for.

@return [Boolean] true if this class name exist, false

otherwise.
# File lib/paru/filter/attr.rb, line 81
def has_class?(name)
    @classes.include? name
end
has_key?(name) click to toggle source

Does this attributes object have this key?

@param name [String] key to find

@return [Boolean] true if this key exist, false otherwise

# File lib/paru/filter/attr.rb, line 71
def has_key?(name)
    @data.key? name
end
to_ast() click to toggle source

Convert this attributes object to an AST representation

@return [Array] Array containing id, class name list, and

key-value pair list
# File lib/paru/filter/attr.rb, line 89
def to_ast
    [
        @id,
        @classes,
        @data.to_a
    ]
end