Class: Hexx::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/hexx/name.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#localeSymbol (readonly)

The locale to be used for naming. Equals I18n.locale by default.


17
# File 'lib/hexx/name.rb', line 17

attr_reader :object, :locale

#objectSymbol (readonly)

The locale to be used for naming. Equals I18n.locale by default.


# File 'lib/hexx/name.rb', line 8

Class Method Details

.for(object, locale: I18n.locale) ⇒ String

Constructs the name for given object and locale.


46
47
48
# File 'lib/hexx/name.rb', line 46

def self.for(object, locale: I18n.locale)
  new(object, locale).for
end

Instance Method Details

#forString

This method is abstract.

Returns the name for the current #object.


36
37
38
# File 'lib/hexx/name.rb', line 36

def for
  ""
end

#object_nameObject (private)


68
69
70
# File 'lib/hexx/name.rb', line 68

def object_name
  self.class.name.underscore.gsub("::", "/")
end

#scopeArray<String, Symbol>

The scope for object translation.


62
63
64
# File 'lib/hexx/name.rb', line 62

def scope
  @scope ||= %w(activemodel models) << object_name
end

#t(value, options = {}) ⇒ String

Translates the value in the current scope and locale.


55
56
57
58
# File 'lib/hexx/name.rb', line 55

def t(value, options = {})
  return value unless value.is_a? Symbol
  I18n.t value, options.merge(locale: locale, scope: scope)
end