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

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

Returns the value of attribute process_chunk.



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

def process_chunk
  @process_chunk
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.context_ok?(_content, _chunk_start) ⇒ Boolean

Returns:

  • (Boolean)


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

def burn_after_reading text
  @burn_read = text
end

#burn_readObject



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

def burn_read
  return unless @burn_read

  tmp = @burn_read
  @burn_read = nil
  tmp
end

#cardObject



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

def card
  @content.card
end

#formatObject



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

def format
  @content.format
end

#inspectObject



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

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

#interpret(_match_string, _content) ⇒ Object



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



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

def reference_code
  "I"
end

#resultObject



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

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

#to_sObject



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

def to_s
  result
end