Class: I18n::Locale::Tag::Rfc4646

Inherits:
Struct
  • Object
show all
Includes:
Parents
Defined in:
lib/i18n/locale/tag/rfc4646.rb

Defined Under Namespace

Modules: Parser

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parents

#parent, #parents, #self_and_parents

Class Method Details

.parserObject



25
26
27
# File 'lib/i18n/locale/tag/rfc4646.rb', line 25

def parser
  @@parser ||= Rfc4646::Parser
end

.parser=(parser) ⇒ Object



29
30
31
# File 'lib/i18n/locale/tag/rfc4646.rb', line 29

def parser=(parser)
  @@parser = parser
end

.tag(tag) ⇒ Object

Parses the given tag and returns a Tag instance if it is valid. Returns false if the given tag is not valid according to RFC 4646.



20
21
22
23
# File 'lib/i18n/locale/tag/rfc4646.rb', line 20

def tag(tag)
  matches = parser.match(tag)
  new(*matches) if matches
end

Instance Method Details

#to_aObject



48
49
50
# File 'lib/i18n/locale/tag/rfc4646.rb', line 48

def to_a
  members.collect { |attr| self.send(attr) }
end

#to_sObject



44
45
46
# File 'lib/i18n/locale/tag/rfc4646.rb', line 44

def to_s
  @tag ||= to_a.compact.join("-")
end

#to_symObject



40
41
42
# File 'lib/i18n/locale/tag/rfc4646.rb', line 40

def to_sym
  to_s.to_sym
end