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

Inherits:
Object
  • Object
show all
Defined in:
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 '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_chunkObject (readonly)

Returns the value of attribute process_chunk.



12
13
14
# File 'lib/card/content/chunk/abstract.rb', line 12

def process_chunk
  @process_chunk
end

#textObject (readonly)

Returns the value of attribute text.



12
13
14
# File 'lib/card/content/chunk/abstract.rb', line 12

def text
  @text
end

Class Method Details

.context_ok?(_content, _chunk_start) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File '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 '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 '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 '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 'lib/card/content/chunk/abstract.rb', line 73

def burn_after_reading text
  @burn_read = text
end

#burn_readObject



62
63
64
65
66
67
68
# File 'lib/card/content/chunk/abstract.rb', line 62

def burn_read
  return unless @burn_read

  tmp = @burn_read
  @burn_read = nil
  tmp
end

#cardObject



50
51
52
# File 'lib/card/content/chunk/abstract.rb', line 50

def card
  @content.card
end

#formatObject



46
47
48
# File 'lib/card/content/chunk/abstract.rb', line 46

def format
  @content.format
end

#inspectObject



77
78
79
# File 'lib/card/content/chunk/abstract.rb', line 77

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

#interpret(_match_string, _content) ⇒ Object



41
42
43
44
# File '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_codeObject



29
30
31
# File 'lib/card/content/chunk/abstract.rb', line 29

def reference_code
  "I"
end

#resultObject



58
59
60
# File 'lib/card/content/chunk/abstract.rb', line 58

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

#to_sObject



54
55
56
# File 'lib/card/content/chunk/abstract.rb', line 54

def to_s
  result
end