Class: Card::Content::Chunk::Abstract
- Inherits:
-
Object
- Object
- Card::Content::Chunk::Abstract
show all
- Defined in:
- card/lib/card/content/chunk/abstract.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(match, content) ⇒ Abstract
Returns a new instance of Abstract.
33
34
35
36
37
38
39
|
# File 'card/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
Returns the value of attribute process_chunk.
12
13
14
|
# File 'card/lib/card/content/chunk/abstract.rb', line 12
def process_chunk
@process_chunk
end
|
Returns the value of attribute text.
12
13
14
|
# File 'card/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 'card/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 'card/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 'card/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 'card/lib/card/content/chunk/abstract.rb', line 81
def as_json _options={}
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 'card/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 'card/lib/card/content/chunk/abstract.rb', line 62
def burn_read
return unless @burn_read
tmp = @burn_read
@burn_read = nil
tmp
end
|
50
51
52
|
# File 'card/lib/card/content/chunk/abstract.rb', line 50
def card
@content.card
end
|
46
47
48
|
# File 'card/lib/card/content/chunk/abstract.rb', line 46
def format
@content.format
end
|
77
78
79
|
# File 'card/lib/card/content/chunk/abstract.rb', line 77
def inspect
"<##{self.class}##{self}>"
end
|
#interpret(_match_string, _content) ⇒ Object
41
42
43
44
|
# File 'card/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 'card/lib/card/content/chunk/abstract.rb', line 29
def reference_code
"I"
end
|
58
59
60
|
# File 'card/lib/card/content/chunk/abstract.rb', line 58
def result
burn_read || @process_chunk || @processed || @text
end
|
54
55
56
|
# File 'card/lib/card/content/chunk/abstract.rb', line 54
def to_s
result
end
|