Class: Card::Content::Chunk::Abstract
- Inherits:
-
Object
- Object
- Card::Content::Chunk::Abstract
show all
- Defined in:
- lib/card/content/chunk.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.
116
117
118
119
120
121
122
123
|
# File 'lib/card/content/chunk.rb', line 116
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
self
end
|
Instance Attribute Details
#process_chunk ⇒ Object
Returns the value of attribute process_chunk.
95
96
97
|
# File 'lib/card/content/chunk.rb', line 95
def process_chunk
@process_chunk
end
|
#text ⇒ Object
Returns the value of attribute text.
95
96
97
|
# File 'lib/card/content/chunk.rb', line 95
def text
@text
end
|
Class Method Details
.context_ok?(_content, _chunk_start) ⇒ Boolean
107
108
109
|
# File 'lib/card/content/chunk.rb', line 107
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
99
100
101
|
# File 'lib/card/content/chunk.rb', line 99
def full_match content, prefix=nil
content.match full_re(prefix)
end
|
.full_re(_prefix) ⇒ Object
103
104
105
|
# File 'lib/card/content/chunk.rb', line 103
def full_re _prefix
config[:full_re]
end
|
Instance Method Details
#as_json(_options = {}) ⇒ Object
165
166
167
168
|
# File 'lib/card/content/chunk.rb', line 165
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
157
158
159
|
# File 'lib/card/content/chunk.rb', line 157
def burn_after_reading text
@burn_read = text
end
|
#burn_read ⇒ Object
146
147
148
149
150
151
152
|
# File 'lib/card/content/chunk.rb', line 146
def burn_read
return unless @burn_read
tmp = @burn_read
@burn_read = nil
tmp
end
|
#card ⇒ Object
134
135
136
|
# File 'lib/card/content/chunk.rb', line 134
def card
@content.card
end
|
130
131
132
|
# File 'lib/card/content/chunk.rb', line 130
def format
@content.format
end
|
#inspect ⇒ Object
161
162
163
|
# File 'lib/card/content/chunk.rb', line 161
def inspect
"<##{self.class}##{self}>"
end
|
#interpret(_match_string, _content) ⇒ Object
125
126
127
128
|
# File 'lib/card/content/chunk.rb', line 125
def interpret _match_string, _content
Rails.logger.info "no #interpret method found for chunk class: " \
"#{self.class}"
end
|
#reference_code ⇒ Object
112
113
114
|
# File 'lib/card/content/chunk.rb', line 112
def reference_code
"I"
end
|
#result ⇒ Object
142
143
144
|
# File 'lib/card/content/chunk.rb', line 142
def result
burn_read || @process_chunk || @processed || @text
end
|
#to_s ⇒ Object
138
139
140
|
# File 'lib/card/content/chunk.rb', line 138
def to_s
result
end
|