Class: RubyBBCode::TagInfo
- Inherits:
-
Object
- Object
- RubyBBCode::TagInfo
- 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
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#allowed_in?(parent_tag) ⇒ Boolean
Returns true if the tag element is allowed in the provided parent_tag.
-
#can_have_quick_param? ⇒ Boolean
Returns true if this tag has quick parameter support.
-
#definition ⇒ Object
Returns the definition of this instance (when it represents a tag element).
-
#element_is_closing_tag? ⇒ Boolean
Returns true if this instance represents a closing tag element.
-
#element_is_opening_tag? ⇒ Boolean
Returns true if this instance represents an opening tag element.
-
#element_is_tag? ⇒ Boolean
Returns true if this instance represents a tag element.
-
#element_is_text? ⇒ Boolean
Returns true if this instance represents a text element.
-
#handle_tag_as_text ⇒ Object
Converts this instance (from a tag) into a text element.
-
#initialize(tag_info, dictionary) ⇒ TagInfo
constructor
A new instance of TagInfo.
-
#invalid_quick_param? ⇒ Boolean
Returns true if the tag param matches the regex pattern defined in tags.rb.
-
#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.
-
#tag_in_dictionary? ⇒ Boolean
Returns true if this tag element is included in the set of available tags.
-
#text ⇒ Object
Returns the text (when this instance represents a text element).
-
#type ⇒ Object
Returns the type of the cuvvrent tag/node, which is either :opening_tag, :closing_tag, or :text.
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
73 74 75 |
# File 'lib/ruby-bbcode/tag_info.rb', line 73 def allowed_in?(parent_tag) ! or @definition[:only_in].include?(parent_tag) end |
#can_have_quick_param? ⇒ Boolean
Returns true if this tag has quick parameter support
78 79 80 |
# File 'lib/ruby-bbcode/tag_info.rb', line 78 def can_have_quick_param? @definition[:allow_quick_param] end |
#definition ⇒ Object
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
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
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
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
48 49 50 |
# File 'lib/ruby-bbcode/tag_info.rb', line 48 def element_is_text? !self[:is_tag] end |
#handle_tag_as_text ⇒ Object
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
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.
68 69 70 |
# File 'lib/ruby-bbcode/tag_info.rb', line 68 def !@definition[:only_in].nil? end |
#tag_in_dictionary? ⇒ Boolean
Returns true if this tag element is included in the set of available tags
63 64 65 |
# File 'lib/ruby-bbcode/tag_info.rb', line 63 def tag_in_dictionary? !@definition.nil? end |
#text ⇒ Object
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 |
#type ⇒ Object
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 |