Class: RubyBBCode::TagNode

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-bbcode/tag_node.rb

Overview

A TagNode specifies either an opening tag element or a (plain) text elements

TagInfo elements are essentially converted into these nodes which are later converted into html output in the bbtree_to_html method

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, nodes = []) ⇒ TagNode

Attributes

  • element - contains the information of TagInfo#tag_data. A text element has the form of

    { :is_tag=>false, :text=>"ITALIC" }
    

    and a tag element has the form of

    { :is_tag=>true, :tag=>:i, :nodes => [] }
    
  • nodes



18
19
20
# File 'lib/ruby-bbcode/tag_node.rb', line 18

def initialize(element, nodes = [])
  @element = element
end

Instance Attribute Details

#elementObject

Tag or text element that is stored in this node



8
9
10
# File 'lib/ruby-bbcode/tag_node.rb', line 8

def element
  @element
end

Instance Method Details

#[](key) ⇒ Object



22
23
24
# File 'lib/ruby-bbcode/tag_node.rb', line 22

def [](key)
  @element[key]
end

#[]=(key, value) ⇒ Object



26
27
28
# File 'lib/ruby-bbcode/tag_node.rb', line 26

def []=(key, value)
  @element[key] = value
end

#allow_params?Boolean

Returns true if the tag is allowed to have parameters

Returns:

  • (Boolean)


36
37
38
# File 'lib/ruby-bbcode/tag_node.rb', line 36

def allow_params?
  definition[:param_tokens]
end

#childrenObject

Return an list containing the child nodes of this node.



61
62
63
# File 'lib/ruby-bbcode/tag_node.rb', line 61

def children
  @element[:nodes]
end

#definitionObject

shows the tag definition for this TagNode as defined in tags.rb



56
57
58
# File 'lib/ruby-bbcode/tag_node.rb', line 56

def definition
  @element[:definition]
end

#has_children?Boolean

Returns true id the node that child nodes

Returns:

  • (Boolean)


46
47
48
# File 'lib/ruby-bbcode/tag_node.rb', line 46

def has_children?
  type == :tag and children.length > 0
end

#invalid_quick_param?Boolean

Returns true when the quick parameter was invalid (i.e. it did not match the required format)

Returns:

  • (Boolean)


51
52
53
# File 'lib/ruby-bbcode/tag_node.rb', line 51

def invalid_quick_param?
  @element.key? :invalid_quick_param
end

#params_not_set?Boolean

Returns true if the tag does not have any parameters set.

Returns:

  • (Boolean)


41
42
43
# File 'lib/ruby-bbcode/tag_node.rb', line 41

def params_not_set?
  @element[:params].length == 0
end

#typeObject

Returns :tag is the node is a tag node, and :text if the node is a text node



31
32
33
# File 'lib/ruby-bbcode/tag_node.rb', line 31

def type
  @element[:is_tag] ? :tag : :text
end