Class: Card::Content::Chunk::Abstract
- Inherits:
-
Object
- Object
- Card::Content::Chunk::Abstract
- Defined in:
- lib/card/content/chunk/abstract.rb
Overview
Abstract class used for all different types of chunks of card content
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.
34 35 36 37 38 39 40 |
# File 'lib/card/content/chunk/abstract.rb', line 34 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.
13 14 15 |
# File 'lib/card/content/chunk/abstract.rb', line 13 def process_chunk @process_chunk end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
13 14 15 |
# File 'lib/card/content/chunk/abstract.rb', line 13 def text @text end |
Class Method Details
.context_ok?(_content, _chunk_start) ⇒ Boolean
25 26 27 |
# File 'lib/card/content/chunk/abstract.rb', line 25 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
17 18 19 |
# File 'lib/card/content/chunk/abstract.rb', line 17 def full_match content, prefix=nil content.match full_re(prefix) end |
.full_re(_prefix) ⇒ Object
21 22 23 |
# File 'lib/card/content/chunk/abstract.rb', line 21 def full_re _prefix config[:full_re] end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
82 83 84 85 |
# File 'lib/card/content/chunk/abstract.rb', line 82 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
74 75 76 |
# File 'lib/card/content/chunk/abstract.rb', line 74 def burn_after_reading text @burn_read = text end |
#burn_read ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/card/content/chunk/abstract.rb', line 63 def burn_read return unless @burn_read tmp = @burn_read @burn_read = nil tmp end |
#card ⇒ Object
51 52 53 |
# File 'lib/card/content/chunk/abstract.rb', line 51 def card @content.card end |
#format ⇒ Object
47 48 49 |
# File 'lib/card/content/chunk/abstract.rb', line 47 def format @content.format end |
#inspect ⇒ Object
78 79 80 |
# File 'lib/card/content/chunk/abstract.rb', line 78 def inspect "<##{self.class}##{self}>" end |
#interpret(_match_string, _content) ⇒ Object
42 43 44 45 |
# File 'lib/card/content/chunk/abstract.rb', line 42 def interpret _match_string, _content Rails.logger.info "no #interpret method found for chunk class: " \ "#{self.class}" end |
#reference_code ⇒ Object
30 31 32 |
# File 'lib/card/content/chunk/abstract.rb', line 30 def reference_code "I" end |
#result ⇒ Object
59 60 61 |
# File 'lib/card/content/chunk/abstract.rb', line 59 def result burn_read || @process_chunk || @processed || @text end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/card/content/chunk/abstract.rb', line 55 def to_s result end |