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(tag) ⇒ Object
logic when popping specific tag.
- #push(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
67 68 69 70 71 |
# File 'lib/bbcoder/buffer_tags.rb', line 67 def criteria_met?(tag) return false if BBCoder.configuration[tag].nil? parent_criteria_met?(BBCoder.configuration[tag].parents) end |
#empty? ⇒ Boolean
54 55 56 |
# File 'lib/bbcoder/buffer_tags.rb', line 54 def empty? _internal.empty? end |
#include?(tag) ⇒ Boolean
62 63 64 |
# File 'lib/bbcoder/buffer_tags.rb', line 62 def include?(tag) _internal.include?(tag) end |
#join(limit = nil) ⇒ Object
orphaned open tags are combined
41 42 43 44 45 46 47 |
# File 'lib/bbcoder/buffer_tags.rb', line 41 def join(limit = nil) limit = size if limit.nil? 1.upto(limit).to_a.collect do [BBCoder::Tag.reform(_internal.pop, .delete(size+1)), buffer.pop(+1)].join # +1 depth modifier for the buffer end.reverse.join end |
#last ⇒ Object
58 59 60 |
# File 'lib/bbcoder/buffer_tags.rb', line 58 def last _internal.last end |
#parent_criteria_met?(parents) ⇒ Boolean
73 74 75 |
# File 'lib/bbcoder/buffer_tags.rb', line 73 def parent_criteria_met?(parents) parents.empty? || !(_internal & parents).empty? end |
#pop(tag) ⇒ Object
logic when popping specific tag
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bbcoder/buffer_tags.rb', line 28 def pop(tag) if empty? || !include?(tag) buffer.push("[/#{tag}]") elsif last == tag buffer.push(BBCoder::Tag.to_html(_internal.pop, .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(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(tag) tag, = if tag.include?("=") splits = tag.split("=") [splits.shift.to_sym, splits.join] else [tag.to_sym, nil] end if criteria_met?(tag) _internal.push(tag) [size] = else buffer.push(BBCoder::Tag.reform(tag, )) end end |
#size ⇒ Object
delegates to _internal
50 51 52 |
# File 'lib/bbcoder/buffer_tags.rb', line 50 def size _internal.size end |