Class: BazaModels::ClassTranslation
- Inherits:
-
Object
- Object
- BazaModels::ClassTranslation
- Defined in:
- lib/baza_models/class_translation.rb
Instance Method Summary collapse
- #class_name_snake ⇒ Object
- #human(args = {}) ⇒ Object
- #i18n_key ⇒ Object
-
#initialize(args) ⇒ ClassTranslation
constructor
A new instance of ClassTranslation.
- #param_key ⇒ Object
- #route_key ⇒ Object
- #singular_route_key ⇒ Object
Constructor Details
#initialize(args) ⇒ ClassTranslation
Returns a new instance of ClassTranslation.
2 3 4 |
# File 'lib/baza_models/class_translation.rb', line 2 def initialize(args) @klass = args.fetch(:class) end |
Instance Method Details
#class_name_snake ⇒ Object
6 7 8 |
# File 'lib/baza_models/class_translation.rb', line 6 def class_name_snake @class_name_snake ||= StringCases.camel_to_snake(@klass.name) end |
#human(args = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/baza_models/class_translation.rb', line 10 def human(args = {}) if args[:count] && args[:count] >= 2 count_key = "other" else count_key = "one" end keys = [ "baza_models.models.#{class_name_snake}.#{count_key}", "activerecord.models.#{class_name_snake}.#{count_key}" ] keys.each do |key| return I18n.t(key) if I18n.exists?(key) end @klass.name end |
#i18n_key ⇒ Object
41 42 43 |
# File 'lib/baza_models/class_translation.rb', line 41 def i18n_key param_key.to_sym end |
#param_key ⇒ Object
29 30 31 |
# File 'lib/baza_models/class_translation.rb', line 29 def param_key @param_key ||= class_name_snake end |
#route_key ⇒ Object
33 34 35 |
# File 'lib/baza_models/class_translation.rb', line 33 def route_key "#{param_key}s" end |
#singular_route_key ⇒ Object
37 38 39 |
# File 'lib/baza_models/class_translation.rb', line 37 def singular_route_key param_key end |