Class: Card::Content::Chunk::Abstract
- Inherits:
-
Object
- Object
- Card::Content::Chunk::Abstract
show all
- Defined in:
- card/lib/card/content/chunk/abstract.rb
Overview
Abstract class used for all different types of chunks of card content
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(match, content) ⇒ Abstract
Returns a new instance of Abstract.
34
35
36
37
38
39
40
|
# File 'card/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
Returns the value of attribute process_chunk.
13
14
15
|
# File 'card/lib/card/content/chunk/abstract.rb', line 13
def process_chunk
@process_chunk
end
|
Returns the value of attribute text.
13
14
15
|
# File 'card/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 'card/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 'card/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 'card/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 'card/lib/card/content/chunk/abstract.rb', line 82
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
74
75
76
|
# File 'card/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 'card/lib/card/content/chunk/abstract.rb', line 63
def burn_read
return unless @burn_read
tmp = @burn_read
@burn_read = nil
tmp
end
|
51
52
53
|
# File 'card/lib/card/content/chunk/abstract.rb', line 51
def card
@content.card
end
|
47
48
49
|
# File 'card/lib/card/content/chunk/abstract.rb', line 47
def format
@content.format
end
|
78
79
80
|
# File 'card/lib/card/content/chunk/abstract.rb', line 78
def inspect
"<##{self.class}##{self}>"
end
|
#interpret(_match_string, _content) ⇒ Object
42
43
44
45
|
# File 'card/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 'card/lib/card/content/chunk/abstract.rb', line 30
def reference_code
"I"
end
|
59
60
61
|
# File 'card/lib/card/content/chunk/abstract.rb', line 59
def result
burn_read || @process_chunk || @processed || @text
end
|
55
56
57
|
# File 'card/lib/card/content/chunk/abstract.rb', line 55
def to_s
result
end
|