Class: Locale::Tag::Cldr
Constants
Name | Value |
---|---|
VARIANT | "(#{ALPHANUM}{5,8}|#{DIGIT}#{ALPHANUM}{3})" |
EXTENSION | "#{ALPHANUM}+=[a-z0-9\-]+" |
TAG_RE | /\A#{LANGUAGE}(?:[-_]#{SCRIPT})? (?:[-_]#{REGION})?((?:[-_]#{VARIANT})* (?:@(#{EXTENSION};?)+)*)\Z/ix |
Attributes
Name | Read/write? |
---|---|
extensions | R |
Public Class Methods
new (language, script = nil, region = nil, variants = [], extensions = {})
Create Locale::Tag::Cldr.
variants should be upcase.
# File lib/locale/tag/cldr.rb, line 58 58: def initialize(language, script = nil, region = nil, 59: variants = [], extensions = {}) 60: @extensions = extensions 61: super(language, script, region, variants.map{|v| v.upcase}) 62: end
parse (tag)
Parse the language tag and return the new Locale::Tag::CLDR.
# File lib/locale/tag/cldr.rb, line 31 31: def parse(tag) 32: if tag =~ /\APOSIX\Z/ # This is the special case of POSIX locale but match this regexp. 33: nil 34: elsif tag =~ TAG_RE 35: lang, script, region, subtag = $1, $2, $3, $4 36: 37: extensions = {} 38: subtag.scan(/#{EXTENSION}/i).each{|v| 39: subtag.sub!(v, "") 40: key, type = v.split("=") 41: extensions[key] = type 42: } 43: variants = subtag.scan(/#{VARIANT}/i).collect{|v| v[0].upcase} 44: 45: ret = self.new(lang, script, region, variants, extensions) 46: ret.tag = tag 47: ret 48: else 49: nil 50: end 51: end
Public Instance Methods
extensions= (val)
Sets the extensions as an Hash.
# File lib/locale/tag/cldr.rb, line 65 65: def extensions=(val) 66: clear 67: @extensions = val 68: end