Class: Brut::I18n::HTTPAcceptLanguage::WeightedLocale

Inherits:
Data
  • Object
show all
Defined in:
lib/brut/i18n/http_accept_language.rb

Overview

A locale with the weight (value for q=) it was given in the Accept-Language header

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#localeObject (readonly)

Returns the value of attribute locale

Returns:

  • (Object)

    the current value of locale



7
8
9
# File 'lib/brut/i18n/http_accept_language.rb', line 7

def locale
  @locale
end

#qObject (readonly)

Returns the value of attribute q

Returns:

  • (Object)

    the current value of q



7
8
9
# File 'lib/brut/i18n/http_accept_language.rb', line 7

def q
  @q
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/brut/i18n/http_accept_language.rb', line 21

def ==(other)
  self.locale == other.locale
end

#primary?Boolean

True if this locale is a primary locale

Returns:

  • (Boolean)


14
# File 'lib/brut/i18n/http_accept_language.rb', line 14

def primary? = self.primary_locale == self.locale

#primary_localeObject

Returns the primary locale for whatever locale this is holding. For example, the primary locale of "en-US" is "en".



11
# File 'lib/brut/i18n/http_accept_language.rb', line 11

def primary_locale = self.locale.gsub(/\-.*$/,"")

#primary_onlyObject

Return a new WeightedLocale that is the primary locale.



17
18
19
# File 'lib/brut/i18n/http_accept_language.rb', line 17

def primary_only
  self.class.new(locale: self.primary_locale, q: self.q)
end