Class: RubyBBCode::TagInfo
- Inherits:
-
Object
- Object
- RubyBBCode::TagInfo
- Defined in:
- lib/ruby-bbcode-to-md/tag_info.rb
Overview
tag info is basically what the regex scan get’s converted into during the tag_sifter#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(tag_symbol) ⇒ Object
- #allowed_outside_parent_tags? ⇒ Boolean
- #can_have_params? ⇒ Boolean
- #constrained_to_within_parent_tags? ⇒ Boolean
- #definition ⇒ Object
- #definition=(val) ⇒ Object
-
#dictionary ⇒ Object
need this for reasigning multi_tag elements.
- #element_is_closing_tag? ⇒ Boolean
- #element_is_opening_tag? ⇒ Boolean
- #element_is_tag? ⇒ Boolean
- #element_is_text? ⇒ Boolean
- #handle_unregistered_tags_as_text ⇒ Object
- #has_params? ⇒ Boolean
-
#initialize(tag_info, dictionary) ⇒ TagInfo
constructor
A new instance of TagInfo.
-
#invalid_param? ⇒ Boolean
Checks if the tag param matches the regex pattern defined in tags.rb.
- #tag_data ⇒ Object
- #tag_missing_from_tag_dictionary? ⇒ Boolean
-
#text ⇒ Object
This represents the text value of the element (if it’s not a tag element) Newlines are converted to html <br /> syntax before being returned.
-
#type ⇒ Object
allows for a very snazy case/ when conditional.
Constructor Details
#initialize(tag_info, dictionary) ⇒ TagInfo
Returns a new instance of TagInfo.
8 9 10 11 12 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 8 def initialize(tag_info, dictionary) @tag_data = find_tag_info(tag_info) @dictionary = dictionary @definition = @dictionary[@tag_data[:tag].to_sym] unless @tag_data[:tag].nil? end |
Instance Method Details
#[](key) ⇒ Object
14 15 16 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 14 def [](key) @tag_data[key] end |
#[]=(key, value) ⇒ Object
18 19 20 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 18 def []=(key, value) @tag_data[key] = value end |
#allowed_in(tag_symbol) ⇒ Object
96 97 98 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 96 def allowed_in(tag_symbol) @definition[:only_in].include?(tag_symbol) end |
#allowed_outside_parent_tags? ⇒ Boolean
88 89 90 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 88 def @definition[:only_in].nil? end |
#can_have_params? ⇒ Boolean
100 101 102 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 100 def can_have_params? @definition[:allow_tag_param] end |
#constrained_to_within_parent_tags? ⇒ Boolean
92 93 94 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 92 def !@definition[:only_in].nil? end |
#definition ⇒ Object
26 27 28 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 26 def definition @definition end |
#definition=(val) ⇒ Object
30 31 32 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 30 def definition=(val) @definition = val end |
#dictionary ⇒ Object
need this for reasigning multi_tag elements
34 35 36 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 34 def dictionary # need this for reasigning multi_tag elements @dictionary end |
#element_is_closing_tag? ⇒ Boolean
72 73 74 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 72 def element_is_closing_tag? self[:closing_tag] end |
#element_is_opening_tag? ⇒ Boolean
68 69 70 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 68 def element_is_opening_tag? self[:is_tag] and !self[:closing_tag] end |
#element_is_tag? ⇒ Boolean
64 65 66 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 64 def element_is_tag? self[:is_tag] end |
#element_is_text? ⇒ Boolean
76 77 78 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 76 def element_is_text? !self[:text].nil? end |
#handle_unregistered_tags_as_text ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 55 def if element_is_tag? and tag_missing_from_tag_dictionary? # Handle as text from now on! self[:is_tag] = false self[:closing_tag] = false self[:text] = self[:complete_match] end end |
#has_params? ⇒ Boolean
80 81 82 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 80 def has_params? self[:params][:tag_param] != nil end |
#invalid_param? ⇒ Boolean
Checks if the tag param matches the regex pattern defined in tags.rb
105 106 107 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 105 def invalid_param? self[:params][:tag_param].match(@definition[:tag_param]).nil? end |
#tag_data ⇒ Object
22 23 24 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 22 def tag_data @tag_data end |
#tag_missing_from_tag_dictionary? ⇒ Boolean
84 85 86 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 84 def tag_missing_from_tag_dictionary? !@dictionary.include?(self[:tag].to_sym) end |
#text ⇒ Object
This represents the text value of the element (if it’s not a tag element) Newlines are converted to html <br /> syntax before being returned.
40 41 42 43 44 45 46 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 40 def text text = @tag_data[:text] # convert_newlines_to_br text.gsub!("\r\n", "\n") text.gsub!("\n", "\n") text end |
#type ⇒ Object
allows for a very snazy case/ when conditional
49 50 51 52 53 |
# File 'lib/ruby-bbcode-to-md/tag_info.rb', line 49 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 |