Class: Tml::Tokens::Method

Inherits:
Data
  • Object
show all
Defined in:
lib/tml/tokens/method.rb

Overview

Method Token Forms

useruser.name

user.name:gender

Instance Attribute Summary

Attributes inherited from Data

#case_keys, #context_keys, #full_name, #label, #short_name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#apply_case, #apply_language_cases, #context_for_language, #decorate, #decoration_name, #error, #initialize, #key, #language_cases_enabled?, #name, #name_for_case_keys, parse, #parse_elements, #sanitize, #sanitized_name, #to_s, #token_object, token_object, #token_value, #token_value_from_array_param, #token_value_from_hash_param, #token_values_from_array

Constructor Details

This class inherits a constructor from Tml::Tokens::Data

Class Method Details

.expressionObject



43
44
45
# File 'lib/tml/tokens/method.rb', line 43

def self.expression
  /(%?\{{1,2}\s*[\w]+\.\w*\s*(:\s*\w+)*\s*(::\s*\w+)*\s*\}{1,2})/
end

Instance Method Details

#object_method_nameObject



51
52
53
# File 'lib/tml/tokens/method.rb', line 51

def object_method_name
  @object_method_name ||= short_name.split(".").last
end

#object_nameObject



47
48
49
# File 'lib/tml/tokens/method.rb', line 47

def object_name
  @object_name ||= short_name.split(".").first
end

#substitute(label, context, language, options = {}) ⇒ Object



55
56
57
58
59
60
# File 'lib/tml/tokens/method.rb', line 55

def substitute(label, context, language, options = {})
  object = Tml::Utils.hash_value(context, object_name)
  return label unless object
  object_value = sanitize(object.send(object_method_name), object, language, options.merge(:safe => false))
  label.gsub(full_name, decorate(object_value, options))
end