Included Modules

Locale::Tag::Rfc

Language tag class for RFC4646(BCP47).

Constants

SINGLETON
VARIANT
EXTENSION
PRIVATEUSE
GRANDFATHERED
TAG_RE

Attributes

extensions[R]
privateuse[R]

Public Class Methods

new(language, script = nil, region = nil, variants = [], extensions = [], privateuse = nil) click to toggle source
    # File lib/locale/tag/rfc.rb, line 61
61:       def initialize(language, script = nil, region = nil, variants = [],
62:                    extensions = [], privateuse = nil)
63:         @extensions, @privateuse = extensions, privateuse
64:         super(language, script, region, variants)
65:       end
parse(tag) click to toggle source

Parse the language tag and return the new Locale::Tag::Rfc.

    # File lib/locale/tag/rfc.rb, line 32
32:         def parse(tag)
33:           if tag =~ /\APOSIX\Z/  # This is the special case of POSIX locale but match this regexp.
34:             nil
35:           elsif tag =~ TAG_RE
36:             lang, script, region, subtag = $1, $2, $3, $4
37:             extensions = []
38:             variants = []
39:             if subtag =~ /#{PRIVATEUSE}/
40:                 subtag, privateuse = $`, $1
41:               # Private use for CLDR.
42:               if /x-ldml(.*)/ =~ privateuse
43:                 p_subtag = $1 
44:                 extensions = p_subtag.scan(/(^|-)#{EXTENSION}/).collect{|v| p_subtag.sub!(v[1], ""); v[1]}
45:                 variants = p_subtag.scan(/(^|-)#{VARIANT}(?=(-|$))/).collect{|v| v[1]}
46:               end
47:             end
48:             extensions += subtag.scan(/(^|-)#{EXTENSION}/).collect{|v| subtag.sub!(v[1], ""); v[1]}
49:             variants += subtag.scan(/(^|-)#{VARIANT}(?=(-|$))/).collect{|v| v[1]}
50:             
51:             ret = self.new(lang, script, region, variants, extensions, privateuse)
52:             ret.tag = tag
53:             ret
54:           else
55:             nil
56:           end
57:         end

Public Instance Methods

extensions=(val) click to toggle source

Sets the extensions as an Array.

    # File lib/locale/tag/rfc.rb, line 68
68:       def extensions=(val)
69:         clear
70:         @extensions = val
71:       end
privateuse=(val) click to toggle source

Sets the privateuse as a String

    # File lib/locale/tag/rfc.rb, line 74
74:       def privateuse=(val)
75:         clear
76:         @privateuse = val
77:       end

Private Instance Methods

convert_to(klass) click to toggle source
    # File lib/locale/tag/rfc.rb, line 80
80:       def convert_to(klass)
81:         if klass == Rfc
82:           klass.new(language, script, region, variants, extensions, privateuse)
83:         elsif klass == Cldr
84:           exts = {}
85:           extensions.sort.each do |v|
86:             if v =~ /^k-(#{ALPHANUM}{2,})-(.*)$/
87:               exts[$1] = $2
88:             end
89:           end
90:           klass.new(language, script, region, variants, exts)
91:         else
92:           super
93:         end
94:       end
to_string() click to toggle source

Returns the language tag

  <language>-<Script>-<REGION>-<variants>-<extensions>-<PRIVATEUSE>
  (e.g.) "ja-Hira-JP-variant"

This is used in internal only. Use to_s instead.

     # File lib/locale/tag/rfc.rb, line 101
101:       def to_string
102:         s = super.gsub(/_/, "-")
103:         @extensions.sort.each do |v|
104:           s << "-#{v}"
105:         end
106:         s << "-#{@privateuse}" if @privateuse
107:         s
108:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.