Class: Tr8n::Tokens::MethodToken
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Tr8n::Token
#allowed_in_translation?, #apply_case, #case_key, #caseless_name, #declared_name, #decoration?, #dependant?, #dependencies, #dependency, #dependency_rules, #evaluate_token_method_array, #full_name, #has_case_key?, #has_type?, #initialize, #language_rule, #language_rules, #name, #name_for_case, #name_key, #name_with_case, #original_label, parse, #permutable_name, #pipeless_name, #prepare_label_for_suggestion, #prepare_label_for_translator, register_data_tokens, register_decoration_tokens, #sanitize_token_value, #sanitized_name, #sanitized_name_for_case, #supports_cases?, #to_s, #token_array_value, #token_value, #type
Constructor Details
This class inherits a constructor from Tr8n::Token
Class Method Details
.expression ⇒ Object
36
37
38
|
# File 'lib/tr8n/tokens/method_token.rb', line 36
def self.expression
/(\{[^_:.][\w]*(\.[\w]+)(:[\w]+)?(::[\w]+)?\})/
end
|
Instance Method Details
#object_method_name ⇒ Object
44
45
46
|
# File 'lib/tr8n/tokens/method_token.rb', line 44
def object_method_name
@object_method_name ||= name.split(".").last
end
|
#object_name ⇒ Object
40
41
42
|
# File 'lib/tr8n/tokens/method_token.rb', line 40
def object_name
@object_name ||= name.split(".").first
end
|
#substitute(label, values = {}, options = {}, language = Tr8n::Config.current_language) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/tr8n/tokens/method_token.rb', line 52
def substitute(label, values = {}, options = {}, language = Tr8n::Config.current_language)
object = values[object_name.to_sym]
raise Tr8n::TokenException.new("Missing value for a token: #{full_name}") unless object
object_value = sanitize_token_value(object, object.send(object_method_name), options.merge(:sanitize_values => true), language)
label.gsub(full_name, object_value)
end
|
#suffix ⇒ Object
48
49
50
|
# File 'lib/tr8n/tokens/method_token.rb', line 48
def suffix
@suffix ||= object_name.split('_').last
end
|