Class: SatoriLikeDictionary::TemplateContext

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/satori_like_dictionary.rb

Overview

template runtime context class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events, request) ⇒ TemplateContext

initialize context

Parameters:

  • events (Events)

    events definition

  • request (OpenStruct)

    request hash



247
248
249
250
# File 'lib/satori_like_dictionary.rb', line 247

def initialize(events, request)
  @events = events
  @request = request
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

method_missing



272
273
274
275
276
277
278
# File 'lib/satori_like_dictionary.rb', line 272

def method_missing(method_name, *args)
  if result = method_name.match(/^r(\d+)$/) # r0 -> request.Reference0
    request["Reference#{result[1]}"]
  else
    super
  end
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



242
243
244
# File 'lib/satori_like_dictionary.rb', line 242

def events
  @events
end

#requestObject (readonly)

Returns the value of attribute request.



242
243
244
# File 'lib/satori_like_dictionary.rb', line 242

def request
  @request
end

Instance Method Details

#call_to(target_character) ⇒ Object

set communication target

Parameters:

  • target_character (String)

    communication target character name



267
268
269
# File 'lib/satori_like_dictionary.rb', line 267

def call_to(target_character)
  request.__satori_target_character = target_character
end

#change_scopeObject

change character scope



253
254
255
256
257
# File 'lib/satori_like_dictionary.rb', line 253

def change_scope
  scope_info = "__satori_scope_#{self.object_id}"
  request[scope_info] = request[scope_info].nil? || request[scope_info] == 1 ? 0 : 1
  '\\' + request[scope_info].to_s
end

#jump_to(target_entry) ⇒ Object

jump to entry

Parameters:

  • target_entry (String)

    jump target entry name



261
262
263
# File 'lib/satori_like_dictionary.rb', line 261

def jump_to(target_entry)
  "#{target_entry})\\e"
end