class Locale::Tag::Simple

Abstract language tag class. This class has <language>, <region> which all of language tag specifications have.

Constants

ALPHA
ALPHANUM
DIGIT
LANGUAGE
REGION
TAG_RE

Attributes

language[R]
region[R]
tag[RW]

tag is set when .parse method is called. This value is used when the program want to know the original String.

Public Class Methods

new(language, region = nil) click to toggle source

Create a Locale::Tag::Simple

# File lib/locale/tag/simple.rb, line 68
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(tag) click to toggle source

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

# File lib/locale/tag/simple.rb, line 55
def parse(tag)
  case tag
  when TAG_RE
    ret = self.new($1, $2)
    ret.tag = tag
    ret
  else
    nil
  end
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/locale/tag/simple.rb, line 86
def <=>(other)
  self.to_s <=> other.to_s
end
candidates() click to toggle source

Returns an Array of tag-candidates order by priority. Use Locale.candidates instead of this method.

# File lib/locale/tag/simple.rb, line 125
def candidates
  [self.class.new(language, region), self.class.new(language)]
end
country() click to toggle source

For backward compatibility.

# File lib/locale/tag/simple.rb, line 107
def country; region end
language=(val) click to toggle source

Set the language (with downcase)

# File lib/locale/tag/simple.rb, line 110
def language=(val)
  @language = val
  @language = @language.downcase if @language
  @language
end
region=(val) click to toggle source

Set the region (with upcase)

# File lib/locale/tag/simple.rb, line 117
def region=(val)
  @region = val
  @region = @region.upcase if @region
  @region
end
to_s() click to toggle source

Returns the language tag as the String.

<language>_<REGION>
(e.g.) "ja_JP"
# File lib/locale/tag/simple.rb, line 78
def to_s
  to_string
end

Private Instance Methods

to_string() click to toggle source

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 141
def to_string  
  s = @language.dup
  s << "_" << @region if @region
  s      
end