Class: BBCoder::BufferTags
- Inherits:
-
Object
- Object
- BBCoder::BufferTags
- Defined in:
- lib/bbcoder/buffer_tags.rb
Instance Attribute Summary collapse
-
#_internal ⇒ Object
Returns the value of attribute _internal.
-
#_meta ⇒ Object
Returns the value of attribute _meta.
-
#buffer ⇒ Object
Returns the value of attribute buffer.
Instance Method Summary collapse
-
#criteria_met?(tag) ⇒ Boolean
helper methods.
- #empty? ⇒ Boolean
- #include?(tag) ⇒ Boolean
-
#initialize(buffer) ⇒ BufferTags
constructor
A new instance of BufferTags.
-
#join(limit = nil) ⇒ Object
orphaned open tags are combined.
- #last ⇒ Object
- #parent_criteria_met?(parents) ⇒ Boolean
-
#pop(original_tag) ⇒ Object
logic when popping specific tag.
- #push(original_tag) ⇒ Object
-
#size ⇒ Object
delegates to _internal.
Constructor Details
#initialize(buffer) ⇒ BufferTags
Returns a new instance of BufferTags.
5 6 7 8 9 |
# File 'lib/bbcoder/buffer_tags.rb', line 5 def initialize(buffer) @buffer = buffer @_internal = [] @_meta = {} end |
Instance Attribute Details
#_internal ⇒ Object
Returns the value of attribute _internal.
3 4 5 |
# File 'lib/bbcoder/buffer_tags.rb', line 3 def _internal @_internal end |
#_meta ⇒ Object
Returns the value of attribute _meta.
3 4 5 |
# File 'lib/bbcoder/buffer_tags.rb', line 3 def @_meta end |
#buffer ⇒ Object
Returns the value of attribute buffer.
3 4 5 |
# File 'lib/bbcoder/buffer_tags.rb', line 3 def buffer @buffer end |
Instance Method Details
#criteria_met?(tag) ⇒ Boolean
helper methods
75 76 77 78 79 |
# File 'lib/bbcoder/buffer_tags.rb', line 75 def criteria_met?(tag) return false if BBCoder.configuration[tag].nil? parent_criteria_met?(BBCoder.configuration[tag].parents) end |
#empty? ⇒ Boolean
62 63 64 |
# File 'lib/bbcoder/buffer_tags.rb', line 62 def empty? _internal.empty? end |
#include?(tag) ⇒ Boolean
70 71 72 |
# File 'lib/bbcoder/buffer_tags.rb', line 70 def include?(tag) _internal.include?(tag) end |
#join(limit = nil) ⇒ Object
orphaned open tags are combined
48 49 50 51 52 53 54 55 |
# File 'lib/bbcoder/buffer_tags.rb', line 48 def join(limit = nil) limit = size if limit.nil? 1.upto(limit).to_a.collect do # singular tags are caught in the handle method [BBCoder::Tag.handle(_internal.pop, buffer.depth, .delete(size+1)), buffer.pop(+1)].join # +1 depth modifier for the buffer end.reverse.join end |
#last ⇒ Object
66 67 68 |
# File 'lib/bbcoder/buffer_tags.rb', line 66 def last _internal.last end |
#parent_criteria_met?(parents) ⇒ Boolean
81 82 83 |
# File 'lib/bbcoder/buffer_tags.rb', line 81 def parent_criteria_met?(parents) parents.empty? || !(_internal & parents).empty? end |
#pop(original_tag) ⇒ Object
logic when popping specific tag
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bbcoder/buffer_tags.rb', line 28 def pop(original_tag) tag = if original_tag.is_a?(Symbol) original_tag else original_tag.downcase.to_sym end # no more tags left to pop || this tag isn't in the list if empty? || !include?(tag) buffer.push("[/#{original_tag}]") elsif last == tag buffer.push(BBCoder::Tag.to_html(_internal.pop, buffer.depth, .delete(size+1), buffer.pop(+1))) elsif include?(tag) # repeats pop(tag) until we reach the last == tag buffer.push(join(+1)) pop(tag) end end |
#push(original_tag) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bbcoder/buffer_tags.rb', line 11 def push(original_tag) tag, = if original_tag.include?("=") splits = original_tag.split("=") [splits.shift.downcase.to_sym, splits.join('=')] else [original_tag.downcase.to_sym, nil] end if criteria_met?(tag) _internal.push(tag) [size] = else buffer.push(BBCoder::Tag.reform(original_tag, )) end end |
#size ⇒ Object
delegates to _internal
58 59 60 |
# File 'lib/bbcoder/buffer_tags.rb', line 58 def size _internal.size end |