Class: Locale::Tag::Common

### Home Classes Methods

### In Files

- lib/locale/tag/common.rb

### Parent

Locale::Tag::Simple

### Methods

- ::new
- ::parse
- #candidates
- #script=
- #variants=

### 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::Common

Common Language tag class for Ruby. Java and MS Windows use this format.

- ja (language: RFC4646)

- ja_JP (country: RFC4646(2 alpha or 3 digit))

- ja-JP

- ja_Hira_JP (script: 4 characters)

- ja-Hira-JP

- ja_Hira_JP_MOBILE (variants: more than 2 characters or 3 digit)

- ja_Hira_JP_MOBILE_IPHONE (2 variants example)

### Constants

LANGUAGE
SCRIPT
TAG_RE
VARIANT

### Attributes

script[R]
variants[R]

### Public Class Methods

new(language, script = nil, region = nil, variants = []) click to toggle source

Create a Locale::Tag::Common.

    # File lib/locale/tag/common.rb, line 56
    def initialize(language, script = nil, region = nil, variants = [])
      @script, @variants = script, variants
      @script = @script.capitalize  if @script
      super(language, region)
    end

parse(tag) click to toggle source

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

    # File lib/locale/tag/common.rb, line 38
    def parse(tag)
      if tag =~ /\APOSIX\Z/  # This is the special case of POSIX locale but match this regexp.
        nil
      elsif tag =~ TAG_RE
        lang, script, region, subtag = $1, $2, $3, $4
        variants = subtag.scan(/(^|[-_])#{VARIANT}(?=([-_]|$))/).collect{|v| v[1]}

        ret = self.new(lang, script, region, variants)
        ret.tag = tag
        ret
      else
        nil
      end
    end

### Public Instance Methods

candidates() click to toggle source

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

Locale::Tag::Rfc, Cldr don't have their own candidates, because it's meaningless to compare the extensions, privateuse, etc.

    # File lib/locale/tag/common.rb, line 81
    def candidates
      [self.class.new(language, script, region, variants),   #ja-Kana-JP-FOO
       self.class.new(language, script, region),             #ja-Kana-JP
       self.class.new(language, nil, region, variants),      #ja-JP-FOO
       self.class.new(language, nil, region),                #ja-JP
       self.class.new(language, script, nil, variants),      #ja-Kana-FOO
       self.class.new(language, script),                     #ja-Kana
       self.class.new(language, nil, nil, variants),         #ja-FOO
       self.class.new(language)]                             #ja
    end

script=(val) click to toggle source

Set the script (with capitalize)

    # File lib/locale/tag/common.rb, line 63
    def script=(val)
      clear
      @script = val
      @script = @script.capitalize if @script
      @script
    end

variants=(val) click to toggle source

Set the variants as an Array.

    # File lib/locale/tag/common.rb, line 71
    def variants=(val)
      clear
      @variants = val
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.