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


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

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


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

def call_to(target_character)
  request.__satori_target_character = target_character
end

#change_scopeObject

change character scope


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

def change_scope
  request.__satori_scope = request.__satori_scope.nil? || request.__satori_scope == 1 ? 0 : 1
  '\\' + request.__satori_scope.to_s
end

#jump_to(target_entry) ⇒ Object

jump to entry

Parameters:

  • target_entry (String)

    jump target entry name


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

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