Class: Card::Content::Chunk::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/card/content/chunk.rb

Direct Known Subclasses

EscapedLiteral, Reference, URI, ViewStub

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
# File 'lib/card/content/chunk.rb', line 116

def initialize match, content
  @text = match[0]
  @processed = nil
  @content = content
  interpret match, content
  self
end

Instance Attribute Details

#process_chunkObject (readonly)

Returns the value of attribute process_chunk.



95
96
97
# File 'lib/card/content/chunk.rb', line 95

def process_chunk
  @process_chunk
end

#textObject (readonly)

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

Returns:

  • (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



149
150
151
152
# File 'lib/card/content/chunk.rb', line 149

def as_json _options={}
  @process_chunk || @processed ||
    "not rendered #{self.class}, #{card&.name}"
end

#cardObject



133
134
135
# File 'lib/card/content/chunk.rb', line 133

def card
  @content.card
end

#formatObject



129
130
131
# File 'lib/card/content/chunk.rb', line 129

def format
  @content.format
end

#inspectObject



145
146
147
# File 'lib/card/content/chunk.rb', line 145

def inspect
  "<##{self.class}##{self}>"
end

#interpret(_match_string, _content, _params) ⇒ Object



124
125
126
127
# File 'lib/card/content/chunk.rb', line 124

def interpret _match_string, _content, _params
  Rails.logger.info "no #interpret method found for chunk class: " \
                    "#{self.class}"
end

#reference_codeObject



112
113
114
# File 'lib/card/content/chunk.rb', line 112

def reference_code
  "I"
end

#resultObject



141
142
143
# File 'lib/card/content/chunk.rb', line 141

def result
  @process_chunk || @processed || @text
end

#to_sObject



137
138
139
# File 'lib/card/content/chunk.rb', line 137

def to_s
  result
end