class Tr8n::Tokens::Method

Method Token Forms

{user.name}

{user.name:gender}

Public Class Methods

expression() click to toggle source
# File lib/tr8n/tokens/method.rb, line 43
def self.expression
  /(\{[^_:.][\w]*(\.[\w]+)(:[\w]+)*(::[\w]+)*\})/
end

Public Instance Methods

object_method_name() click to toggle source
# File lib/tr8n/tokens/method.rb, line 51
def object_method_name
  @object_method_name ||= short_name.split(".").last
end
object_name() click to toggle source
# File lib/tr8n/tokens/method.rb, line 47
def object_name
  @object_name ||= short_name.split(".").first
end
substitute(label, context, language, options = {}) click to toggle source
# File lib/tr8n/tokens/method.rb, line 55
def substitute(label, context, language, options = {})
  object = Tr8n::Utils.hash_value(context, object_name)
  raise Tr8n::Exception.new("Missing value for a token: #{full_name}") unless object
  object_value = sanitize(object.send(object_method_name), object, language, options.merge(:safe => false))
  label.gsub(full_name, object_value)
end