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_tag_param?Boolean

Returns:

  • (Boolean)


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

def allow_tag_param?
  definition[:allow_tag_param]
end

#childrenObject



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

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:

  • (Boolean)


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

def has_children?
  return false if type == :text or children.length == 0  # text nodes return false too
  return true if children.length > 0
end

#param_not_set?Boolean

Checks to see if the parameter for the TagNode has been set.

Returns:

  • (Boolean)


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

def param_not_set?
  (@element[:params].nil? or @element[:params][:tag_param].nil?)
end

#param_set?Boolean

check if the parameter for the TagNode is set

Returns:

  • (Boolean)


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

def param_set?
  !param_not_set?
end

#tag_param=(param) ⇒ Object

Easy way to set the tag_param value of the hash, which represents the parameter supplied



66
67
68
# File 'lib/ruby-bbcode/tag_node.rb', line 66

def tag_param=(param)
  @element[:params] = {:tag_param => param}
end

#typeObject

Debugging/ visualization purposes



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

def type
  return :tag if @element[:is_tag]
  return :text if !@element[:is_tag]
end