Class: Locale::Tag::Posix

Inherits:
Simple
  • Object
show all
Defined in:
lib/locale/tag/posix.rb

Overview

Locale tag class for POSIX locale

  • ja

  • ja_JP

  • ja_JP.UTF-8

  • ja_JP.UTF-8@Osaka

  • C/POSIX (-> en_US)

Constant Summary collapse

LANGUAGE =
"([a-z]{2,})"
TAG_RE =
/\A#{LANGUAGE}(?:_#{REGION})?(?:\.([^@]+))?(?:@(.*))?\Z/i

Constants inherited from Simple

Simple::ALPHA, Simple::ALPHANUM, Simple::DIGIT, Simple::REGION

Instance Attribute Summary collapse

Attributes inherited from Simple

#language, #region, #tag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Simple

#<=>, #==, #country, #eql?, #hash, #inspect, #to_str

Constructor Details

#initialize(language, region = nil, charset = nil, modifier = nil) ⇒ Posix

Returns a new instance of Posix.



28
29
30
31
# File 'lib/locale/tag/posix.rb', line 28

def initialize(language, region = nil, charset = nil, modifier = nil)
  @charset, @modifier = charset, modifier
  super(language, region)
end

Instance Attribute Details

#charsetObject

Returns the value of attribute charset.



26
27
28
# File 'lib/locale/tag/posix.rb', line 26

def charset
  @charset
end

#modifierObject

Returns the value of attribute modifier.



26
27
28
# File 'lib/locale/tag/posix.rb', line 26

def modifier
  @modifier
end

Class Method Details

.parse(tag) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/locale/tag/posix.rb', line 33

def self.parse(tag)
  case tag
  when /^(C|POSIX)$/
    ret = self.new("en", "US")
    ret.tag = tag
    ret
  when TAG_RE
    ret = self.new($1, $2, $3, $4)
    ret.tag = tag
    ret
  else
    nil
  end
end

Instance Method Details

#candidatesObject

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



71
72
73
74
75
76
77
78
79
80
# File 'lib/locale/tag/posix.rb', line 71

def candidates
  [self.class.new(language, region, charset, modifier),  #ja_JP.UTF-8@Modifier
   self.class.new(language, region, charset),            #ja_JP.UTF-8
   self.class.new(language, region, nil, modifier),      #ja_JP@Modifier
   self.class.new(language, region, nil, nil),           #ja_JP@Modifier
   self.class.new(language, nil, charset, modifier),     #ja.UTF-8@Modifier
   self.class.new(language, nil, charset),               #ja.UTF-8
   self.class.new(language, nil, nil, modifier),         #ja@Modifier
   self.class.new(language)]                             #ja
end

#to_sObject

Returns the language tag.

<language>_<COUNTRY>.<CHARSET>@<MODIFIER>
(e.g.) "ja_JP.EUC-JP@Modifier"


51
52
53
54
55
56
57
# File 'lib/locale/tag/posix.rb', line 51

def to_s
  s = @language.dup
  s << "_#{@region}" if @region
  s << ".#{@charset}" if @charset
  s << "@#{@modifier}" if @modifier
  s
end