Class: Locale::Tag::Simple
- Inherits:
-
Object
- Object
- Locale::Tag::Simple
- Extended by:
- Util::Memoizable
- Includes:
- Util::Memoizable
- Defined in:
- lib/locale/tag/simple.rb
Overview
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
Constant Summary collapse
- ALPHA =
'[a-z]'
- DIGIT =
'[0-9]'
- ALPHANUM =
"[a-zA-Z0-9]"
- LANGUAGE =
ISO 639
"(#{ALPHA}{2,3})"
- REGION =
RFC4646 (ISO3166/UN M.49)
"(#{ALPHA}{2}|#{DIGIT}{3})"
- TAG_RE =
/\A#{LANGUAGE}(?:[_-]#{REGION})?\Z/i
Constants included from Util::Memoizable
Util::Memoizable::MEMOIZED_IVAR
Instance Attribute Summary collapse
-
#language ⇒ Object
Returns the value of attribute language.
-
#region ⇒ Object
Returns the value of attribute region.
-
#tag ⇒ Object
tag is set when .parse method is called.
Class Method Summary collapse
-
.parse(tag) ⇒ Object
Parse the language tag and return the new Locale::Tag::Simple.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#==(other) ⇒ Object
:nodoc:.
-
#candidates ⇒ Object
Returns an Array of tag-candidates order by priority.
-
#country ⇒ Object
For backward compatibility.
-
#eql?(other) ⇒ Boolean
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(language, region = nil) ⇒ Simple
constructor
Create a Locale::Tag::Simple.
-
#inspect ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
Returns the language tag as the String.
-
#to_str ⇒ Object
:nodoc:.
Methods included from Util::Memoizable
_memoize, _memoize_dup, clear, freeze, freeze_without_memoizable, memoize, memoize_clear, memoize_dup, memoize_impl
Constructor Details
#initialize(language, region = nil) ⇒ Simple
Create a Locale::Tag::Simple
75 76 77 78 79 80 |
# 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 |
Instance Attribute Details
#language ⇒ Object
Returns the value of attribute language.
36 37 38 |
# File 'lib/locale/tag/simple.rb', line 36 def language @language end |
#region ⇒ Object
Returns the value of attribute region.
36 37 38 |
# File 'lib/locale/tag/simple.rb', line 36 def region @region end |
#tag ⇒ Object
tag is set when .parse method is called. This value is used when the program want to know the original String.
41 42 43 |
# File 'lib/locale/tag/simple.rb', line 41 def tag @tag end |
Class Method Details
.parse(tag) ⇒ Object
Parse the language tag and return the new Locale::Tag::Simple.
62 63 64 65 66 67 68 69 70 |
# 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 |
Instance Method Details
#<=>(other) ⇒ Object
94 95 96 |
# File 'lib/locale/tag/simple.rb', line 94 def <=>(other) self.to_s <=> other.to_s end |
#==(other) ⇒ Object
:nodoc:
98 99 100 |
# File 'lib/locale/tag/simple.rb', line 98 def ==(other) #:nodoc: other != nil and hash == other.hash end |
#candidates ⇒ Object
Returns an Array of tag-candidates order by priority. Use Locale.candidates instead of this method.
138 139 140 |
# File 'lib/locale/tag/simple.rb', line 138 def candidates [self.class.new(language, region), self.class.new(language)] end |
#country ⇒ Object
For backward compatibility.
118 |
# File 'lib/locale/tag/simple.rb', line 118 def country; region end |
#eql?(other) ⇒ Boolean
:nodoc:
102 103 104 |
# File 'lib/locale/tag/simple.rb', line 102 def eql?(other) #:nodoc: self.==(other) end |
#hash ⇒ Object
:nodoc:
107 108 109 |
# File 'lib/locale/tag/simple.rb', line 107 def hash #:nodoc: "#{self.class}:#{to_s}".hash end |
#inspect ⇒ Object
:nodoc:
112 113 114 |
# File 'lib/locale/tag/simple.rb', line 112 def inspect #:nodoc: %Q[#<#{self.class}: #{to_s}>] end |
#to_s ⇒ Object
Returns the language tag as the String.
<language>_<REGION>
(e.g.) "ja_JP"
85 86 87 |
# File 'lib/locale/tag/simple.rb', line 85 def to_s to_string end |
#to_str ⇒ Object
:nodoc:
90 91 92 |
# File 'lib/locale/tag/simple.rb', line 90 def to_str #:nodoc: to_s end |