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.

Returns:

  • (Symbol)

    the locale.


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.

Returns:

  • (Symbol)

    the locale.


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

Class Method Details

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

Constructs the name for given object and locale.

Parameters:

  • object (Object)

    The object to be named.

  • locale (Symbol, nil) (defaults to: I18n.locale)

    (I18n.locale) The locale to be used for naming.

Returns:

  • (String)

    the name.


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.

Returns:

  • (String)

    the name.


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.

Returns:

  • (Array<String, Symbol>)

    the list of scopes.


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.

Parameters:

  • value (Symbol, String)

    The value to be translated.

  • options (Hash) (defaults to: {})

    ({}) The options for the translation.

Returns:

  • (String)

    The translation.


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