Class: Card::Content::Chunk::ViewStub

Inherits:
Abstract
  • Object
show all
Defined in:
mod/core/chunk/view_stub.rb

Instance Attribute Summary

Attributes inherited from Abstract

#text

Instance Method Summary collapse

Methods inherited from Abstract

#as_json, #burn_after_reading, #burn_read, #card, context_ok?, #format, full_match, full_re, #inspect, #reference_code, #to_s

Constructor Details

#initialize(text, content) ⇒ ViewStub

Returns a new instance of ViewStub.



14
15
16
# File 'mod/core/chunk/view_stub.rb', line 14

def initialize text, content
  super
end

Instance Method Details

#hex_to_bin(string) ⇒ Object



28
29
30
# File 'mod/core/chunk/view_stub.rb', line 28

def hex_to_bin string
  string.scan(/../).map { |x| x.hex.chr }.join
end

#initial_stub_hash(string) ⇒ Object



23
24
25
26
# File 'mod/core/chunk/view_stub.rb', line 23

def initial_stub_hash string
  JSON.parse(string).symbolize_keys
  # MessagePack.unpack(hex_to_bin(string)).symbolize_keys
end

#interpret(match, _content) ⇒ Object



18
19
20
21
# File 'mod/core/chunk/view_stub.rb', line 18

def interpret match, _content
  @stub_hash = initial_stub_hash match[1]
  interpret_hash_values
end

#interpret_castObject



38
39
40
# File 'mod/core/chunk/view_stub.rb', line 38

def interpret_cast
  @stub_hash[:cast].symbolize_keys!
end

#interpret_format_optsObject



46
47
48
49
50
51
52
# File 'mod/core/chunk/view_stub.rb', line 46

def interpret_format_opts
  hash = @stub_hash[:format_opts]
  hash.symbolize_keys!
  hash[:nest_mode] = hash[:nest_mode].to_sym
  hash[:override] = hash[:override] == "true"
  hash[:context_names].map!(&:to_name)
end

#interpret_hash_valuesObject



32
33
34
35
36
# File 'mod/core/chunk/view_stub.rb', line 32

def interpret_hash_values
  @stub_hash.keys.each do |key|
    send "interpret_#{key}"
  end
end

#interpret_view_optsObject



42
43
44
# File 'mod/core/chunk/view_stub.rb', line 42

def interpret_view_opts
  @stub_hash[:view_opts].symbolize_keys!
end

#process_chunkObject



54
55
56
# File 'mod/core/chunk/view_stub.rb', line 54

def process_chunk
  @processed = format.stub_nest @stub_hash
end

#resultObject



58
59
60
# File 'mod/core/chunk/view_stub.rb', line 58

def result
  @processed
end