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
Public Class Methods
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
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
For each key-value pair of this attributes object
# File lib/paru/filter/attr.rb, line 52 def each @data.each end
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
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
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