class Locale::Tag::Simple
Abstract language tag class. This class has <language>, <region> which all of language tag specifications have.
-
ja (language: ISO 639 (2 or 3 alpha))
-
ja_JP (country: RFC4646 (ISO3166/UN M.49) (2 alpha or 3 digit)
-
ja-JP
-
ja-392
Constants
- ALPHA
- ALPHANUM
- DIGIT
- LANGUAGE
- REGION
- TAG_RE
Attributes
tag is set when .parse method is called. This value is used when the program want to know the original String.
Public Class Methods
Create a Locale::Tag::Simple
# File lib/locale/tag/simple.rb, line 75 def initialize(language, region = nil) raise "language can't be nil." unless language @language, @region = language, region @language = @language.downcase if @language @region = @region.upcase if @region end
Parse the language tag and return the new Locale::Tag::Simple.
# File lib/locale/tag/simple.rb, line 62 def parse(tag) if tag =~ TAG_RE ret = self.new($1, $2) ret.tag = tag ret else nil end end
Public Instance Methods
# File lib/locale/tag/simple.rb, line 94 def <=>(other) self.to_s <=> other.to_s end
Returns an Array of tag-candidates order by priority. Use Locale#candidates instead of this method.
# File lib/locale/tag/simple.rb, line 138 def candidates [self.class.new(language, region), self.class.new(language)] end
For backward compatibility.
# File lib/locale/tag/simple.rb, line 118 def country; region end
Set the language (with downcase)
# File lib/locale/tag/simple.rb, line 121 def language=(val) clear @language = val @language = @language.downcase if @language @language end
Set the region (with upcase)
# File lib/locale/tag/simple.rb, line 129 def region=(val) clear @region = val @region = @region.upcase if @region @region end
Returns the language tag as the String.
<language>_<REGION> (e.g.) "ja_JP"
# File lib/locale/tag/simple.rb, line 85 def to_s to_string end
Private Instance Methods
Return simple language tag which format is“<lanuguage>_<REGION>”. This is to use internal only. Use #to_s instead.
# File lib/locale/tag/simple.rb, line 155 def to_string s = @language.dup s << "_" << @region if @region s end