Class: RubyBBCode::TagInfo

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

Overview

TagInfo is basically what the regex scan get’s converted into during the TagSifter#process_text method. This class was made mostly just to keep track of all of the confusing the logic conditions that are checked.

Instance Method Summary collapse

Constructor Details

#initialize(tag_info, dictionary) ⇒ TagInfo

Returns a new instance of TagInfo.



6
7
8
# File 'lib/ruby-bbcode/tag_info.rb', line 6

def initialize(tag_info, dictionary)
  @tag_data = find_tag_info(tag_info, dictionary)
end

Instance Method Details

#[](key) ⇒ Object



10
11
12
# File 'lib/ruby-bbcode/tag_info.rb', line 10

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

#[]=(key, value) ⇒ Object



14
15
16
# File 'lib/ruby-bbcode/tag_info.rb', line 14

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

#allowed_in?(parent_tag) ⇒ Boolean

Returns true if the tag element is allowed in the provided parent_tag

Returns:

  • (Boolean)


73
74
75
# File 'lib/ruby-bbcode/tag_info.rb', line 73

def allowed_in?(parent_tag)
  !only_allowed_in_parent_tags? or @definition[:only_in].include?(parent_tag)
end

#can_have_quick_param?Boolean

Returns true if this tag has quick parameter support

Returns:

  • (Boolean)


78
79
80
# File 'lib/ruby-bbcode/tag_info.rb', line 78

def can_have_quick_param?
  @definition[:allow_quick_param]
end

#definitionObject

Returns the definition of this instance (when it represents a tag element)



19
20
21
# File 'lib/ruby-bbcode/tag_info.rb', line 19

def definition
  @definition
end

#element_is_closing_tag?Boolean

Returns true if this instance represents a closing tag element

Returns:

  • (Boolean)


58
59
60
# File 'lib/ruby-bbcode/tag_info.rb', line 58

def element_is_closing_tag?
  self[:is_tag] and  self[:closing_tag]
end

#element_is_opening_tag?Boolean

Returns true if this instance represents an opening tag element

Returns:

  • (Boolean)


53
54
55
# File 'lib/ruby-bbcode/tag_info.rb', line 53

def element_is_opening_tag?
  self[:is_tag] and !self[:closing_tag]
end

#element_is_tag?Boolean

Returns true if this instance represents a tag element

Returns:

  • (Boolean)


43
44
45
# File 'lib/ruby-bbcode/tag_info.rb', line 43

def element_is_tag?
  self[:is_tag]
end

#element_is_text?Boolean

Returns true if this instance represents a text element

Returns:

  • (Boolean)


48
49
50
# File 'lib/ruby-bbcode/tag_info.rb', line 48

def element_is_text?
  !self[:is_tag]
end

#handle_tag_as_textObject

Converts this instance (from a tag) into a text element



36
37
38
39
40
# File 'lib/ruby-bbcode/tag_info.rb', line 36

def handle_tag_as_text
  self[:is_tag] = false
  self[:closing_tag] = false
  self[:text] = self[:complete_match]
end

#invalid_quick_param?Boolean

Returns true if the tag param matches the regex pattern defined in tags.rb

Returns:

  • (Boolean)


83
84
85
# File 'lib/ruby-bbcode/tag_info.rb', line 83

def invalid_quick_param?
  @tag_data.key? :invalid_quick_param
end

#only_allowed_in_parent_tags?Boolean

Returns true if the tag that is represented by this instance is restricted on where it is allowed, i.e. if it is restricted by certain parent tags.

Returns:

  • (Boolean)


68
69
70
# File 'lib/ruby-bbcode/tag_info.rb', line 68

def only_allowed_in_parent_tags?
  !@definition[:only_in].nil?
end

#tag_in_dictionary?Boolean

Returns true if this tag element is included in the set of available tags

Returns:

  • (Boolean)


63
64
65
# File 'lib/ruby-bbcode/tag_info.rb', line 63

def tag_in_dictionary?
  !@definition.nil?
end

#textObject

Returns the text (when this instance represents a text element)



24
25
26
# File 'lib/ruby-bbcode/tag_info.rb', line 24

def text
  @tag_data[:text]
end

#typeObject

Returns the type of the cuvvrent tag/node, which is either :opening_tag, :closing_tag, or :text



29
30
31
32
33
# File 'lib/ruby-bbcode/tag_info.rb', line 29

def type
  return :opening_tag if element_is_opening_tag?
  return :text if element_is_text?
  return :closing_tag if element_is_closing_tag?
end