Class: Vinber::Translate

Inherits:
Object
  • Object
show all
Defined in:
lib/vinber/translate.rb

Constant Summary collapse

VALUE_BOOL_LABLE =
"vinber.%{key}"
VALUE_COMMON_LABLE =
"vinber.%{attribute}_%{key}"
VALUE_LABLE =
"vinber.%{klass}.%{attribute}_%{key}"

Instance Method Summary collapse

Constructor Details

#initialize(klass, attribute, attribute_vinber_key) ⇒ Translate

Returns a new instance of Translate.



8
9
10
11
12
13
14
# File 'lib/vinber/translate.rb', line 8

def initialize(klass, attribute, attribute_vinber_key)
  @label = {
    :klass     => (klass.is_a?(Class) ? klass.name : klass),
    :attribute => attribute,
    :key       => attribute_vinber_key
  }
end

Instance Method Details

#labelObject



16
17
18
# File 'lib/vinber/translate.rb', line 16

def label
  @label ||= %()
end

#textObject Also known as: to_s



20
21
22
23
24
# File 'lib/vinber/translate.rb', line 20

def text
  @text ||= I18n.t((VALUE_LABLE % label), default: nil) ||
    I18n.t((VALUE_COMMON_LABLE % label), default: nil) ||
    I18n.t((VALUE_BOOL_LABLE % label), default: label[:key].to_s.humanize)
end