Class: Locale::Tag::Simple

### Home Classes Methods

### In Files

- lib/locale/tag/simple.rb

### Parent

Object

### Methods

- ::new
- ::parse
- #<=>
- #candidates
- #country
- #language=
- #region=
- #to_s

### Included Modules

- Locale::Util::Memoizable

### Class/Module Index

Quicksearch

- Locale
- Locale::Driver
- Locale::Driver::CGI
- Locale::Driver::Env
- Locale::Driver::JRuby
- Locale::Driver::Posix
- Locale::Driver::Win32
- Locale::Driver::Win32::Kernel32
- Locale::Driver::Win32Table
- Locale::Info
- Locale::Info::Language
- Locale::Info::Region
- Locale::Middleware
- Locale::Tag
- Locale::Tag::Cldr
- Locale::Tag::Common
- Locale::Tag::Irregular
- Locale::Tag::Posix
- Locale::Tag::Rfc
- Locale::Tag::Simple
- Locale::TagList
- Locale::Util
- Locale::Util::Memoizable

No matching classes.

# 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

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 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(tag) click to toggle source

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

<=>(other) click to toggle source

    # File lib/locale/tag/simple.rb, line 94
    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 138
    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 118
    def country; region end

language=(val) click to toggle source

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

region=(val) click to toggle source

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

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 85
    def to_s
      to_string
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.