Class: I18n::Inflector::API_Strict

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n-inflector/api_strict.rb

Overview

This class contains common operations that can be performed on inflection data describing strict kinds and tokens assigned to them (used in named patterns). It is used by the regular API and present there as strict instance attribute.

It operates on the database containing instances of InflectionData_Strict indexed by locale names and has methods to access the inflection data in an easy way. It can operate on a database and options passed to initializer; if they aren’t passet it will create them.

Usage

You can access the instance of this class attached to default I18n backend by calling:

I18n.backend.inflector.strict

or in a short form:

I18n.inflector.strict

In most cases using the regular API instance may be sufficient to operate on inflection data, because the regular API (instantiated as I18n.inflector) is aware of strict kinds and can pass calls from API_Strict object if the kind argument given in a method call contains the @ symbol.

For an instance connected to default I18n backend the object containing inflection options is shared with the regular API.

Direct Known Subclasses

API

Instance Method Summary collapse

Constructor Details

#initialize(idb = nil, options = nil) ⇒ API_Strict

Note:

If any given option is nil then a proper object will be created. If it’s given, then it will be referenced, not copied.

Initilizes inflector by connecting to internal databases used for storing inflection data and options.

Parameters:

  • idb (Hash, nil) (defaults to: nil)

    the strict inflections databases indexed by locale

  • options (I18n::Inflector::InflectionOptions, nil) (defaults to: nil)

    the inflection options



57
58
59
60
61
62
# File 'lib/i18n-inflector/api_strict.rb', line 57

def initialize(idb=nil, options=nil)
  @idb      = idb.nil?      ? {} : idb
  @options  = options.nil?  ? I18n::Inflector::InflectionOptions.new : options
  @lazy_locales = LazyHashEnumerator.for(@idb)
  @inflected_locales_cache = Hash.new
end

Instance Method Details

#add_database(db) ⇒ I18n::Inflector::InflectionData_Strict

Note:

It doesn’t create copy of inflection database, it registers the given object.

Attaches InflectionData_Strict instance to the current object.

Parameters:

Returns:

Raises:



87
88
89
90
91
92
93
# File 'lib/i18n-inflector/api_strict.rb', line 87

def add_database(db)
  return nil if db.nil?
  locale = prep_locale(db.locale)
  delete_database(locale)
  @inflected_locales_cache.clear
  @idb[locale] = db
end

#aliases(kind) ⇒ Hash #aliases(kind, locale) ⇒ Hash

Gets inflection aliases belonging to a strict kind and their pointers.

Overloads:

  • #aliases(kind) ⇒ Hash

    Gets inflection aliases (and their pointers) of the given kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of aliases to get

    Returns:

    • (Hash)

      the Hash containing available inflection aliases

  • #aliases(kind, locale) ⇒ Hash

    Gets inflection aliases (and their pointers) of the given kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of aliases to get

    • locale (Symbol)

      the locale to use

    Returns:

    • (Hash)

      the Hash containing available inflection aliases

Returns:

  • (Hash)

    the Hash containing available inflection aliases (alias => target)

Raises:



564
565
566
# File 'lib/i18n-inflector/api_strict.rb', line 564

def aliases(kind=nil, locale=nil)
  each_alias(kind, locale).to_h
end

#default_token(kind) ⇒ Symbol? #default_token(kind, locale) ⇒ Symbol?

Reads default token of the given strict kind.

Overloads:

  • #default_token(kind) ⇒ Symbol?

    This method reads default token of the given kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of tokens

    Returns:

    • (Symbol, nil)

      the default token or nil if there is no default token

  • #default_token(kind, locale) ⇒ Symbol?

    This method reads default token of the given kind and the given locale.

    Parameters:

    • kind (Symbol, String)

      the kind of tokens

    • locale (Symbol)

      the locale to use

    Returns:

    • (Symbol, nil)

      the default token or nil if there is no default token

Returns:

  • (Symbol, nil)

    the default token or nil

Raises:



242
243
244
245
# File 'lib/i18n-inflector/api_strict.rb', line 242

def default_token(kind, locale=nil)
  return nil if (kind.nil? || kind.to_s.empty?)
  data_safe(locale).get_default_token(kind.to_sym)
end

#delete_database(locale)

Note:

It detaches the database from I18n::Inflector::API_Strict instance. Other objects referring to it directly may still use it.

This method returns an undefined value.

Deletes a strict inflections database for the specified locale.

Parameters:

  • locale (Symbol)

    the locale for which the inflections database is to be deleted.

Raises:



103
104
105
106
107
108
# File 'lib/i18n-inflector/api_strict.rb', line 103

def delete_database(locale)
  locale = prep_locale(locale)
  return nil if @idb[locale].nil?
  @inflected_locales_cache.clear
  @idb[locale] = nil
end

#each_alias(kind) ⇒ LazyHashEnumerator #each_alias(kind, locale) ⇒ LazyHashEnumerator

Iterates through inflection aliases belonging to a strict kind and their pointers.

Overloads:

  • #each_alias(kind) ⇒ LazyHashEnumerator

    Iterates through inflection aliases (and their pointers) of the given kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of aliases to get

    Returns:

  • #each_alias(kind, locale) ⇒ LazyHashEnumerator

    Iterates through inflection aliases (and their pointers) of the given kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of aliases to get

    • locale (Symbol)

      the locale to use

    Returns:

Yields:

  • (alias, target)

    optional block in which each alias will be yielded

Yield Parameters:

  • alias (Symbol)

    an alias

  • target (Symbol)

    a name of the target token

Yield Returns:

Returns:

Raises:



545
546
547
548
# File 'lib/i18n-inflector/api_strict.rb', line 545

def each_alias(kind=nil, locale=nil, &block)
  kind = kind.to_s.empty? ? nil : kind.to_sym
  data_safe(locale).each_alias(kind, &block)
end

#each_inflected_localeLazyArrayEnumerator #each_inflected_locale(kind) ⇒ LazyArrayEnumerator Also known as: each_locale, each_supported_locale

Iterates through locales which have configured strict inflection support.

Overloads:

  • #each_inflected_localeLazyArrayEnumerator

    Iterates through locales which have configured inflection support.

    Returns:

  • #each_inflected_locale(kind) ⇒ LazyArrayEnumerator

    Iterates through locales which have configured inflection support for the given kind.

    Parameters:

    • kind (Symbol)

      the identifier of a kind

    Returns:

Yields:

  • (locale)

    optional block in which each kind will be yielded

Yield Parameters:

  • locale (Symbol)

    the inflected locale identifier

Yield Returns:

Returns:



142
143
144
145
146
147
# File 'lib/i18n-inflector/api_strict.rb', line 142

def each_inflected_locale(kind=nil, &block)
  kind = kind.to_s.empty? ? nil : kind.to_sym
  i = @lazy_locales.reject  { |lang,data| data.empty?           }
  i = i.select              { |lang,data| data.has_kind?(kind)  } unless kind.nil?
  i.each_key(&block)
end

#kindsLazyArrayEnumerator #kinds(locale) ⇒ LazyArrayEnumerator Also known as: each_inflection_kind

Iterates through known strict inflection kinds.

Overloads:

  • #kindsLazyArrayEnumerator

    Iterates through known inflection kinds for the current locale.

    Returns:

  • #kinds(locale) ⇒ LazyArrayEnumerator

    Iterates through known inflection kinds for the given locale.

    Parameters:

    • locale (Symbol)

      the locale for which kinds should be listed

    Returns:

Yields:

  • (kind)

    optional block in which each kind will be yielded

Yield Parameters:

  • kind (Symbol)

    the inflection kind

Yield Returns:

Returns:

Raises:



185
186
187
# File 'lib/i18n-inflector/api_strict.rb', line 185

def each_kind(locale=nil, &block)
  data_safe(locale).each_kind(&block)
end

#each_token(kind) ⇒ LazyHashEnumerator #each_token(kind, locale) ⇒ LazyHashEnumerator

Note:

You cannot deduce where aliases are pointing to, since the information about a target is replaced by the description. To get targets use the #raw_tokens method. To simply list aliases and their targets use the #aliases method.

Iterates through available inflection tokens belonging to a strict kind and their descriptions.

Overloads:

  • #each_token(kind) ⇒ LazyHashEnumerator

    Iterates through available inflection tokens and their descriptions for some kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    Returns:

  • #each_token(kind, locale) ⇒ LazyHashEnumerator

    Iterates through available inflection tokens and their descriptions of the given kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    • locale (Symbol)

      the locale to use

    Returns:

Yields:

  • (token, description)

    optional block in which each token will be yielded

Yield Parameters:

  • token (Symbol)

    a token

  • description (String)

    a description string for a token

Yield Returns:

Returns:

Raises:



394
395
396
397
# File 'lib/i18n-inflector/api_strict.rb', line 394

def each_token(kind=nil, locale=nil, &block)
  kind = kind.to_s.empty? ? nil : kind.to_sym
  data_safe(locale).each_token(kind, &block)
end

#each_token_raw(kind) ⇒ LazyHashEnumerator #each_token_raw(kind, locale) ⇒ LazyHashEnumerator Also known as: each_raw_token

Note:

You may deduce whether the returned values are aliases or true tokens by testing if a value is a kind of Symbol or a String.

Iterates through available inflection tokens belonging to a strict kind and their values.

Overloads:

  • #each_token_raw(kind) ⇒ LazyHashEnumerator

    Iterates through available inflection tokens and their values of the given kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    Returns:

  • #each_token_raw(kind, locale) ⇒ LazyHashEnumerator

    Iterates through available inflection tokens (and their values) of the given kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    • locale (Symbol)

      the locale to use

    Returns:

Yields:

  • (token, value)

    optional block in which each token will be yielded

Yield Parameters:

  • token (Symbol)

    a token

  • value (Symbol, String)

    a description string for a token or a target (if alias)

Yield Returns:

Returns:

Raises:



446
447
448
449
# File 'lib/i18n-inflector/api_strict.rb', line 446

def each_token_raw(kind=nil, locale=nil, &block)
  kind = kind.to_s.empty? ? nil : kind.to_sym
  data_safe(locale).each_raw_token(kind, &block)
end

#each_token_true(kind) ⇒ LazyHashEnumerator #each_token_true(kind, locale) ⇒ LazyHashEnumerator Also known as: each_true_token

Note:

It returns only true tokens, not aliases.

Iterates through inflection tokens belonging to a strict kind and their values.

Overloads:

  • #each_token_true(kind) ⇒ LazyHashEnumerator

    Iterates through true inflection tokens (and their values) of the given kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    Returns:

  • #each_token_true(kind, locale) ⇒ LazyHashEnumerator

    Iterates through true inflection tokens (and their values) of the given kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    • locale (Symbol)

      the locale to use

    Returns:

Yields:

  • (token, description)

    optional block in which each token will be yielded

Yield Parameters:

  • token (Symbol)

    a token

  • description (String)

    a description string for a token

Yield Returns:

Returns:

Raises:



498
499
500
501
# File 'lib/i18n-inflector/api_strict.rb', line 498

def each_token_true(kind=nil, locale=nil, &block)
  kind = kind.to_s.empty? ? nil : kind.to_sym
  data_safe(locale).each_true_token(kind, &block)
end

#has_alias?(token, kind) ⇒ Boolean #has_alias?(token, kind, locale) ⇒ Boolean Also known as: token_is_alias?

Checks if the given token belonging to a strict kind is an alias.

Overloads:

  • #has_alias?(token, kind) ⇒ Boolean

    Uses the current locale and the given kind to check if the given token is an alias.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • kind (Symbol, String)

      the kind of the given token

    Returns:

    • (Boolean)

      true if the given token is an alias, false otherwise

  • #has_alias?(token, kind, locale) ⇒ Boolean

    Uses the given locale and kind to check if the given token is an alias.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • kind (Symbol, String)

      the kind of the given token

    • locale (Symbol)

      the locale to use

    Returns:

    • (Boolean)

      true if the given token is an alias, false otherwise

Returns:

  • (Boolean)

    true if the given token is an alias, false otherwise

Raises:



264
265
266
267
268
# File 'lib/i18n-inflector/api_strict.rb', line 264

def has_alias?(*args)
  token, kind, locale = tkl_args(args)
  return false if (token.nil? || kind.nil?)
  data_safe(locale).has_alias?(token, kind)
end

#has_kind?(kind) ⇒ Boolean #has_kind?(kind, locale) ⇒ Boolean

Tests if a strict kind exists.

Overloads:

  • #has_kind?(kind) ⇒ Boolean

    Tests if a strict kind exists for the current locale.

    Parameters:

    • kind (Symbol)

      the identifier of a kind

    Returns:

    • (Boolean)

      true if the given kind exists, false otherwise

  • #has_kind?(kind, locale) ⇒ Boolean

    Tests if a strict kind exists for the given locale.

    Parameters:

    • kind (Symbol, String)

      the identifier of a kind

    • locale (Symbol)

      the locale identifier

    Returns:

    • (Boolean)

      true if the given kind exists, false otherwise

Returns:

  • (Boolean)

    true if the given kind exists, false otherwise

Raises:



221
222
223
224
# File 'lib/i18n-inflector/api_strict.rb', line 221

def has_kind?(kind, locale=nil)
  return false if (kind.nil? || kind.to_s.empty?)
  data_safe(locale).has_kind?(kind.to_sym)
end

#has_token?(token, kind) ⇒ Boolean #has_token?(token, kind, locale) ⇒ Boolean Also known as: token_exists?

Checks if the given token belonging to a strict kind exists. It may be an alias or a true token.

Overloads:

  • #has_token?(token, kind) ⇒ Boolean

    Uses the current locale and the given kind kind to check if the given token exists.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • kind (Symbol, String)

      the kind of the given token

    Returns:

    • (Boolean)

      true if the given token exists, false otherwise

  • #has_token?(token, kind, locale) ⇒ Boolean

    Uses the given locale and kind to check if the given token exists.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • kind (Symbol, String)

      the kind of the given token

    • locale (Symbol)

      the locale to use

    Returns:

    • (Boolean)

      true if the given token exists, false otherwise

Returns:

  • (Boolean)

    true if the given token exists, false otherwise

Raises:



312
313
314
315
316
# File 'lib/i18n-inflector/api_strict.rb', line 312

def has_token?(*args)
  token, kind, locale = tkl_args(args)
  return false if (token.nil? || kind.nil?)
  data_safe(locale).has_token?(token, kind)
end

#has_true_token?(token, kind) ⇒ Boolean #has_true_token?(token, kind, locale) ⇒ Boolean Also known as: token_is_true?

Checks if the given token belonging to a strict kind is a true token (not alias).

Overloads:

  • #has_true_token?(token, kind) ⇒ Boolean

    Uses the current locale and the given kind to check if the given token is a true token.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • kind (Symbol, String)

      the kind of the given token

    Returns:

    • (Boolean)

      true if the given token is a true token, false otherwise

  • #has_true_token?(token, kind, locale) ⇒ Boolean

    Uses the given locale and kind to check if the given token is a true token.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • kind (Symbol, String)

      the kind of the given token

    • locale (Symbol)

      the locale to use

    Returns:

    • (Boolean)

      true if the given token is a true token, false otherwise

Returns:

  • (Boolean)

    true if the given token is a true token, false otherwise

Raises:



288
289
290
291
292
# File 'lib/i18n-inflector/api_strict.rb', line 288

def has_true_token?(*args)
  token, kind, locale = tkl_args(args)
  return false if (token.nil? || kind.nil?)
  data_safe(locale).has_true_token?(token, kind)
end

#inflected_locale?Boolean #inflected_locale?(locale) ⇒ Boolean Also known as: locale?, locale_supported?

Checks if the given locale was configured to support strict inflection.

Overloads:

  • #inflected_locale?Boolean

    Checks if the current locale was configured to support inflection.

    Returns:

    • (Boolean)

      true if the current locale supports inflection

  • #inflected_locale?(locale) ⇒ Boolean

    Checks if the given locale was configured to support inflection.

    Parameters:

    • locale (Symbol)

      the locale to test

    Returns:

    • (Boolean)

      true if the given locale supports inflection

Returns:

  • (Boolean)

    true if a locale supports inflection

Raises:



122
123
124
# File 'lib/i18n-inflector/api_strict.rb', line 122

def inflected_locale?(locale=nil)
  not @idb[prep_locale(locale)].nil? rescue false
end

#inflected_localesArray<Symbol> #inflected_locales(kind) ⇒ Array<Symbol> Also known as: locales, supported_locales

Gets locales which have configured strict inflection support.

Overloads:

  • #inflected_localesArray<Symbol>

    Gets locales which have configured inflection support.

    Returns:

    • (Array<Symbol>)

      the array containing locales that support inflection

  • #inflected_locales(kind) ⇒ Array<Symbol>

    Gets locales which have configured inflection support for the given kind.

    Parameters:

    • kind (Symbol)

      the identifier of a kind

    Returns:

    • (Array<Symbol>)

      the array containing locales that support inflection

Returns:

  • (Array<Symbol>)

    the array containing locales that support inflection



162
163
164
165
166
# File 'lib/i18n-inflector/api_strict.rb', line 162

def inflected_locales(kind=nil)
  kind = kind.to_s.empty? ? nil : kind.to_sym
  r = ( @inflected_locales_cache[kind] ||= each_inflected_locale(kind).to_a )
  r.nil? ? r : r.dup
end

#kind(token, kind) ⇒ Symbol? #kind(token, kind, locale) ⇒ Symbol?

Gets a kind of the given token (which may be an alias) belonging to a strict kind.

Overloads:

  • #kind(token, kind) ⇒ Symbol?

    Uses current locale and the given kind to get a kind of the given token (which may be an alias).

    Parameters:

    • token (Symbol, String)

      name of the token or alias

    • kind (Symbol, String)

      the identifier of a kind (expectations filter)

    Returns:

    • (Symbol, nil)

      the kind of the given token or nil

  • #kind(token, kind, locale) ⇒ Symbol?

    Uses the given locale to get a kind of the given token (which may be an alias).

    Parameters:

    • token (Symbol, String)

      name of the token or alias

    • kind (Symbol, String)

      the identifier of a kind (expectations filter)

    • locale (Symbol)

      the locale to use

    Returns:

    • (Symbol, nil)

      the kind of the given token or nil

Returns:

  • (Symbol, nil)

    the kind of the given token or nil

Raises:



365
366
367
368
# File 'lib/i18n-inflector/api_strict.rb', line 365

def kind(token, kind=nil, locale=nil)
  return nil if (token.nil? || kind.nil? || token.to_s.empty? || kind.to_s.empty?)
  data_safe(locale).get_kind(token.to_sym, kind.to_sym)
end

#kindsArray<Symbol> #kinds(locale) ⇒ Array<Symbol> Also known as: inflection_kinds

Gets known strict inflection kinds.

Overloads:

  • #kindsArray<Symbol>

    Gets known inflection kinds for the current locale.

    Returns:

    • (Array<Symbol>)

      the array containing known inflection kinds

  • #kinds(locale) ⇒ Array<Symbol>

    Gets known inflection kinds for the given locale.

    Parameters:

    • locale (Symbol)

      the locale for which kinds should be listed

    Returns:

    • (Array<Symbol>)

      the array containing known inflection kinds

Returns:

  • (Array<Symbol>)

    the array containing known inflection kinds

Raises:



202
203
204
# File 'lib/i18n-inflector/api_strict.rb', line 202

def kinds(locale=nil)
  each_kind(locale).to_a
end

#new_database(locale) ⇒ I18n::Inflector::InflectionData_Strict

Creates an empty strict inflections database for the specified locale.

Parameters:

  • locale (Symbol)

    the locale for which the inflections database should be created

Returns:

Raises:



72
73
74
75
76
# File 'lib/i18n-inflector/api_strict.rb', line 72

def new_database(locale)
  locale = prep_locale(locale)
  @inflected_locales_cache.clear
  @idb[locale] = I18n::Inflector::InflectionData_Strict.new(locale)
end

#prep_locale(locale = nil) ⇒ Symbol (protected)

Note:

If the locale is not correct, it tries to use locale from I18n.locale and validates it as well.

Processes locale identifier and validates whether it’s correct (not empty and not nil).

Parameters:

  • locale (Symbol, String) (defaults to: nil)

    the locale identifier

Returns:

  • (Symbol)

    the given locale or the global locale

Raises:



653
654
655
656
657
# File 'lib/i18n-inflector/api_strict.rb', line 653

def prep_locale(locale=nil)
  locale ||= I18n.locale
  raise I18n::InvalidLocale.new(locale) if locale.to_s.empty?
  locale.to_sym
end

#tkl_args(token, kind, locale) ⇒ Array<Symbol,Symbol,Symbol> (protected) #tkl_args(token, kind) ⇒ Array<Symbol,Symbol,Symbol> (protected) #tkl_args(token) ⇒ Array<Symbol,Symbol,Symbol> (protected)

This method is the internal helper that prepares arguments containing token, kind and locale.

Overloads:

  • #tkl_args(token, kind, locale) ⇒ Array<Symbol,Symbol,Symbol>

    Prepares arguments containing token, kind and locale.

    Parameters:

    • token (String, Hash)

      the token

    • kind (String, Hash)

      the inflection kind

    • locale (String, Hash)

      the locale identifier

    Returns:

    • (Array<Symbol,Symbol,Symbol>)

      the array containing cleaned and validated token, kind and locale

  • #tkl_args(token, kind) ⇒ Array<Symbol,Symbol,Symbol>

    Prepares arguments containing token and locale.

    Parameters:

    • token (String, Hash)

      the token

    • kind (String, Hash)

      the inflection kind

    Returns:

    • (Array<Symbol,Symbol,Symbol>)

      the array containing cleaned and validated token, kind and locale

  • #tkl_args(token) ⇒ Array<Symbol,Symbol,Symbol>

    Prepares arguments containing token.

    Parameters:

    • token (String, Hash)

      the token

    Returns:

    • (Array<Symbol,Symbol,Symbol>)

      the array containing cleaned and validated token and the current locale

Returns:

  • (Array<Symbol,Symbol,Symbol>)

    the array containing cleaned and validated token, kind and locale

Raises:



632
633
634
635
636
637
638
639
640
641
642
# File 'lib/i18n-inflector/api_strict.rb', line 632

def tkl_args(args)
  token, kind, locale = case args.count
  when 1 then [args[0], nil, nil]
  when 2 then [args[0], args[1], nil]
  when 3 then args
  else raise I18n::ArgumentError.new("wrong number of arguments: #{args.count} for (1..3)")
  end
  token = token.nil? || token.to_s.empty? ? nil : token.to_sym
  kind  = kind.nil?  || kind.to_s.empty?  ? nil : kind.to_sym
  [token,kind,locale]
end

#token_description(token, kind) ⇒ String? #token_description(token, kind, locale) ⇒ String?

Note:

If the given token is really an alias it returns the description of the true token that it points to.

Gets the description of the given inflection token belonging to a strict kind.

Overloads:

  • #token_description(token, kind) ⇒ String?

    Uses the current locale and the given token to get a description of that token.

    Parameters:

    • token (Symbol, String)

      the token

    • kind (Symbol, String)

      the identifier of a kind

    Returns:

    • (String, nil)

      the descriptive string or nil if something went wrong (e.g. token was not found)

  • #token_description(token, kind, locale) ⇒ String?

    Uses the given locale and the given token to get a description of that token.

    Parameters:

    • token (Symbol, String)

      the token

    • kind (Symbol, String)

      the identifier of a kind

    • locale (Symbol)

      the locale to use

    Returns:

    • (String, nil)

      the descriptive string or nil if something went wrong (e.g. token was not found)

Returns:

  • (String, nil)

    the descriptive string or nil

Raises:



589
590
591
592
593
# File 'lib/i18n-inflector/api_strict.rb', line 589

def token_description(*args)
  token, kind, locale = tkl_args(args)
  return nil if (token.nil? || kind.nil?)
  data_safe(locale).get_description(token, kind)
end

#tokens(kind) ⇒ Hash #tokens(kind, locale) ⇒ Hash

Note:

You cannot deduce where aliases are pointing to, since the information about a target is replaced by the description. To get targets use the #raw_tokens method. To simply list aliases and their targets use the #aliases method.

Gets available inflection tokens belonging to a strict kind and their descriptions.

Overloads:

  • #tokens(kind) ⇒ Hash

    Gets available inflection tokens and their descriptions for some kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    Returns:

    • (Hash)

      the hash containing available inflection tokens (including aliases) as keys and their descriptions as values

  • #tokens(kind, locale) ⇒ Hash

    Gets available inflection tokens and their descriptions of the given kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    • locale (Symbol)

      the locale to use

    Returns:

    • (Hash)

      the hash containing available inflection tokens (including aliases) as keys and their descriptions as values

Returns:

  • (Hash)

    the hash containing available inflection tokens and descriptions

Raises:



421
422
423
# File 'lib/i18n-inflector/api_strict.rb', line 421

def tokens(kind=nil, locale=nil)
  each_token(kind, locale).to_h
end

#tokens_raw(kind) ⇒ Hash #tokens_raw(kind, locale) ⇒ Hash Also known as: raw_tokens

Note:

You may deduce whether the returned values are aliases or true tokens by testing if a value is a kind of Symbol or a String.

Gets available inflection tokens belonging to a strict kind and their values.

Overloads:

  • #tokens_raw(kind) ⇒ Hash

    Gets available inflection tokens and their values of the given kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    Returns:

    • (Hash)

      the hash containing available inflection tokens as keys and their descriptions as values; in case of aliases the returned values are Symbols

  • #tokens_raw(kind, locale) ⇒ Hash

    Gets available inflection tokens (and their values) of the given kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    • locale (Symbol)

      the locale to use

    Returns:

    • (Hash)

      the hash containing available inflection tokens as keys and their descriptions as values. In case of aliases the returned values are Symbols

Returns:

  • (Hash)

    the hash containing available inflection tokens and descriptions (or alias pointers)

Raises:



473
474
475
# File 'lib/i18n-inflector/api_strict.rb', line 473

def tokens_raw(kind=nil, locale=nil)
  each_token_raw(kind, locale).to_h
end

#tokens_true(kind) ⇒ Hash #tokens_true(kind, locale) ⇒ Hash Also known as: true_tokens

Note:

It returns only true tokens, not aliases.

Gets true inflection tokens belonging to a strict kind and their values.

Overloads:

  • #tokens_true(kind) ⇒ Hash

    Gets true inflection tokens (and their values) of the given kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    Returns:

    • (Hash)

      the hash containing available inflection tokens as keys and their descriptions as values

  • #tokens_true(kind, locale) ⇒ Hash

    Gets true inflection tokens (and their values) of the given kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    • locale (Symbol)

      the locale to use

    Returns:

    • (Hash)

      the hash containing available inflection tokens as keys and their descriptions as values

Returns:

  • (Hash)

    the hash containing available inflection tokens and descriptions

Raises:



522
523
524
# File 'lib/i18n-inflector/api_strict.rb', line 522

def tokens_true(kind=nil, locale=nil)
  each_token_true(kind, locale).to_h
end

#true_token(token, kind) ⇒ Symbol? #true_token(token, kind, locale) ⇒ Symbol? Also known as: resolve_alias

Gets true token for the given token belonging to a strict kind. If the token is an alias it will be resolved and a true token (target) will be returned.

Overloads:

  • #true_token(token, kind) ⇒ Symbol?

    Uses the current locale and the given kind to get a real token for the given token. If the token is an alias it will be resolved and a true token (target) will be returned.

    Parameters:

    • token (Symbol, String)

      the identifier of the checked token

    • kind (Symbol, String)

      the identifier of a kind

    Returns:

    • (Symbol, nil)

      the true token or nil

  • #true_token(token, kind, locale) ⇒ Symbol?

    Uses the given locale and kind to get a real token for the given token. If the token is an alias it will be resolved and a true token (target) will be returned.

    Parameters:

    • token (Symbol, String)

      the identifier of the checked token

    • kind (Symbol, String)

      the identifier of a kind

    • locale (Symbol)

      the locale to use

    Returns:

    • (Symbol, nil)

      the true token or nil

Returns:

  • (Symbol, nil)

    the true token or nil

Raises:



341
342
343
344
345
# File 'lib/i18n-inflector/api_strict.rb', line 341

def true_token(*args)
  token, kind, locale = tkl_args(args)
  return nil if (token.nil? || kind.nil?)
  data_safe(locale).get_true_token(token, kind)
end