Class: Card::Content::Chunk::Abstract
- Inherits:
-
Object
- Object
- Card::Content::Chunk::Abstract
- Defined in:
- lib/card/content/chunk/abstract.rb
Instance Attribute Summary collapse
-
#process_chunk ⇒ Object
readonly
Returns the value of attribute process_chunk.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
- .context_ok?(_content, _chunk_start) ⇒ Boolean
-
.full_match(content, prefix = nil) ⇒ Object
if the prefix regex matched check that chunk against the full regex.
- .full_re(_prefix) ⇒ Object
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#burn_after_reading(text) ⇒ Object
Temporarily overrides the processed nest content for single-use After using the nest’s result (for example via ‘to_s`) the original result is restored.
- #burn_read ⇒ Object
- #card ⇒ Object
- #format ⇒ Object
-
#initialize(match, content) ⇒ Abstract
constructor
A new instance of Abstract.
- #inspect ⇒ Object
- #interpret(_match_string, _content) ⇒ Object
- #reference_code ⇒ Object
- #result ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(match, content) ⇒ Abstract
Returns a new instance of Abstract.
33 34 35 36 37 38 39 |
# File 'lib/card/content/chunk/abstract.rb', line 33 def initialize match, content match = self.class.full_match(match) if match.is_a? String @text = match[0] @processed = nil @content = content interpret match, content end |
Instance Attribute Details
#process_chunk ⇒ Object (readonly)
Returns the value of attribute process_chunk.
12 13 14 |
# File 'lib/card/content/chunk/abstract.rb', line 12 def process_chunk @process_chunk end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
12 13 14 |
# File 'lib/card/content/chunk/abstract.rb', line 12 def text @text end |
Class Method Details
.context_ok?(_content, _chunk_start) ⇒ Boolean
24 25 26 |
# File 'lib/card/content/chunk/abstract.rb', line 24 def context_ok? _content, _chunk_start true end |
.full_match(content, prefix = nil) ⇒ Object
if the prefix regex matched check that chunk against the full regex
16 17 18 |
# File 'lib/card/content/chunk/abstract.rb', line 16 def full_match content, prefix=nil content.match full_re(prefix) end |
.full_re(_prefix) ⇒ Object
20 21 22 |
# File 'lib/card/content/chunk/abstract.rb', line 20 def full_re _prefix config[:full_re] end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
81 82 83 84 |
# File 'lib/card/content/chunk/abstract.rb', line 81 def as_json ={} burn_read || @process_chunk || @processed || "not rendered #{self.class}, #{card&.name}" end |
#burn_after_reading(text) ⇒ Object
Temporarily overrides the processed nest content for single-use After using the nest’s result (for example via ‘to_s`) the original result is restored
73 74 75 |
# File 'lib/card/content/chunk/abstract.rb', line 73 def burn_after_reading text @burn_read = text end |
#burn_read ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/card/content/chunk/abstract.rb', line 62 def burn_read return unless @burn_read tmp = @burn_read @burn_read = nil tmp end |
#card ⇒ Object
50 51 52 |
# File 'lib/card/content/chunk/abstract.rb', line 50 def card @content.card end |
#format ⇒ Object
46 47 48 |
# File 'lib/card/content/chunk/abstract.rb', line 46 def format @content.format end |
#inspect ⇒ Object
77 78 79 |
# File 'lib/card/content/chunk/abstract.rb', line 77 def inspect "<##{self.class}##{self}>" end |
#interpret(_match_string, _content) ⇒ Object
41 42 43 44 |
# File 'lib/card/content/chunk/abstract.rb', line 41 def interpret _match_string, _content Rails.logger.info "no #interpret method found for chunk class: " \ "#{self.class}" end |
#reference_code ⇒ Object
29 30 31 |
# File 'lib/card/content/chunk/abstract.rb', line 29 def reference_code "I" end |
#result ⇒ Object
58 59 60 |
# File 'lib/card/content/chunk/abstract.rb', line 58 def result burn_read || @process_chunk || @processed || @text end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/card/content/chunk/abstract.rb', line 54 def to_s result end |