File: taglist.rb

package info (click to toggle)
ruby-locale 2.0.5-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 552 kB
  • sloc: ruby: 4,536; makefile: 2
file content (105 lines) | stat: -rw-r--r-- 2,460 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
=begin
  taglist.rb - Locale module

  Copyright (C) 2008  Masao Mutoh

  You may redistribute it and/or modify it under the same
  license terms as Ruby.

  $Id: taglist.rb 27 2008-12-03 15:06:50Z mutoh $
=end

require 'locale/util/memoizable'

module Locale
  # This provides the subclass of Array which behaves like 
  # the first(top priority) Locale::Tag object. 
  # "Locale.current.language" is same with "Locale.current[0].language".
  #
  # Locale.current returns an Array of Tag(s) now.
  # But the old Locale.current(Ruby-GetText) and Locale.get 
  # returns Locale::Object (similier with Locale::Tag::Posix). 
  # This is the class for backward compatibility.
  #
  # It is recommanded to use Locale.current[0] or 
  # Locale.candidates to find the current locale instead
  # of this function.
  #
  class TagList < Array 
    include Util::Memoizable

    # Returns the top priority language. (simple)
    def language
      self[0].language
    end
    # Returns the top priority region/country. (simple)
    def country
      self[0].region
    end
    # Returns the top priority region/country. (simple)
    def region
      self[0].region
    end
    # Returns the top priority script. (common)
    def script
      self[0].script
    end
    # Returns the top priority charset. (posix)
    def charset
      self[0].respond_to?(:charset) and self[0].charset or ::Locale.driver_module.charset
    end
    memoize :charset

    # Returns the top priority modifier. (posix)
    def modifier
      (self[0].respond_to? :modifier) ? self[0].modifier : nil
    end
    memoize :modifier

    # Returns the top priority variants.(common, rfc, cldr)
    def variants
      (self[0].respond_to? :variants) ? self[0].variants : nil
    end
    memoize :variants

    # Returns the top priority extensions.(common, rfc, cldr)
    def extensions
      (self[0].respond_to? :extensions) ? self[0].extensions : nil
    end
    memoize :extensions

    # Returns the top priority privateuse(rfc)
    def privateuse
      (self[0].respond_to? :privateuse) ? self[0].privateuse : nil
    end
    memoize :privateuse

    def to_str
      self[0].to_str
    end

    def to_s
      self[0].to_s
    end
    
    def to_common
      self[0].to_common
    end

    def to_simple
      self[0].to_simple
    end

    def to_rfc
      self[0].to_rfc
    end

    def to_cldr
      self[0].to_cldr
    end

    def to_posix
      self[0].to_posix
    end
  end
end