Class: Locale::Tag::Cldr
Overview
Unicode locale identifier class for CLDR-1.6.1. (Unicode Common Locale Data Repository).
Constant Summary collapse
- VARIANT =
"(#{ALPHANUM}{5,8}|#{DIGIT}#{ALPHANUM}{3})"
- EXTENSION =
"#{ALPHANUM}+=[a-z0-9\-]+"
- TAG_RE =
/\A#{LANGUAGE}(?:[-_]#{SCRIPT})? (?:[-_]#{REGION})?((?:[-_]#{VARIANT})* (?:@(#{EXTENSION};?)+)*)\Z/ix
Constants inherited from Common
Locale::Tag::Common::LANGUAGE, Locale::Tag::Common::SCRIPT
Constants inherited from Simple
Simple::ALPHA, Simple::ALPHANUM, Simple::DIGIT, Simple::LANGUAGE, Simple::REGION
Instance Attribute Summary collapse
-
#extensions ⇒ Object
Returns the value of attribute extensions.
Attributes inherited from Common
Attributes inherited from Simple
Class Method Summary collapse
-
.parse(tag) ⇒ Object
Parse the language tag and return the new Locale::Tag::CLDR.
Instance Method Summary collapse
-
#initialize(language, script = nil, region = nil, variants = [], extensions = {}) ⇒ Cldr
constructor
Create Locale::Tag::Cldr.
Methods inherited from Common
Methods inherited from Simple
#<=>, #==, #candidates, #country, #eql?, #hash, #inspect, #to_s, #to_str
Constructor Details
#initialize(language, script = nil, region = nil, variants = [], extensions = {}) ⇒ Cldr
Create Locale::Tag::Cldr.
variants should be upcase.
58 59 60 61 62 |
# File 'lib/locale/tag/cldr.rb', line 58 def initialize(language, script = nil, region = nil, variants = [], extensions = {}) @extensions = extensions super(language, script, region, variants.map{|v| v.upcase}) end |
Instance Attribute Details
#extensions ⇒ Object
Returns the value of attribute extensions.
27 28 29 |
# File 'lib/locale/tag/cldr.rb', line 27 def extensions @extensions end |
Class Method Details
.parse(tag) ⇒ Object
Parse the language tag and return the new Locale::Tag::CLDR.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/locale/tag/cldr.rb', line 31 def parse(tag) case tag when /\APOSIX\Z/ # This is the special case of POSIX locale but match this regexp. nil when TAG_RE lang, script, region, subtag = $1, $2, $3, $4 extensions = {} subtag.scan(/#{EXTENSION}/i).each{|v| subtag.sub!(v, "") key, type = v.split("=") extensions[key] = type } variants = subtag.scan(/#{VARIANT}/i).collect{|v| v[0].upcase} ret = self.new(lang, script, region, variants, extensions) ret.tag = tag ret else nil end end |