lang 0.1.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ require 'lang/tag'
2
+
3
+ module Lang #:nodoc:
4
+ module Tag
5
+
6
+ # Lookup.
7
+ # RFC 4647, Section 3.4.
8
+ #
9
+ module Lookup
10
+
11
+ #--
12
+ # RFC 4647, Section 3.4
13
+ #
14
+ # In the lookup scheme, the language range is progressively truncated
15
+ # from the end until a matching language tag is located. Single letter
16
+ # or digit subtags (including both the letter 'x', which introduces
17
+ # private-use sequences, and the subtags that introduce extensions) are
18
+ # removed at the same time as their closest trailing subtag. For
19
+ # example, starting with the range "zh-Hant-CN-x-private1-private2"
20
+ # (Chinese, Traditional script, China, two private-use tags) the lookup
21
+ # progressively searches for content as shown below:
22
+ #
23
+ # Example of a Lookup Fallback Pattern
24
+ #
25
+ # Range to match: zh-Hant-CN-x-private1-private2
26
+ # 1. zh-Hant-CN-x-private1-private2
27
+ # 2. zh-Hant-CN-x-private1
28
+ # 3. zh-Hant-CN
29
+ # 4. zh-Hant
30
+ # 5. zh
31
+ # 6. (default)
32
+ #++
33
+
34
+ def lookup_candidates(min_subtags_count = 1)
35
+ subtags = to_a
36
+ return nil if min_subtags_count < 1 || subtags.size < min_subtags_count
37
+
38
+ candidates = []
39
+ for i in (min_subtags_count - 1)..(subtags.size - 1) do
40
+ next if subtags[i].size == 1
41
+ candidates.unshift subtags[0..i].join(HYPHEN)
42
+ end
43
+ candidates
44
+ end
45
+
46
+ def in?(range)
47
+ range = Composition === range ? range.composition : range.to_str.downcase
48
+ return true if composition == range
49
+ range.index(composition) == 0
50
+ end
51
+
52
+ end
53
+
54
+ #--
55
+ # Lookup is defined for the language tags only.
56
+ #
57
+ # RFC 4647, Section 3.4
58
+ # Lookup is used to select the single language tag that best matches
59
+ # the language priority list for a given request.
60
+ #++
61
+
62
+ class Langtag
63
+ include Lookup
64
+ end
65
+
66
+ class Grandfathered
67
+ include Lookup
68
+ end
69
+
70
+ class Privateuse
71
+ include Lookup
72
+ end
73
+
74
+ end
75
+ end
76
+
77
+ # EOF
@@ -0,0 +1,31 @@
1
+ module Lang #:nodoc:
2
+ module Tag
3
+
4
+ module PATTERN
5
+
6
+ #--
7
+ # RFC 5646, sec. 2.2.2:
8
+ # Although the ABNF production 'extlang' permits up to three
9
+ # extended language tags in the language tag, extended language
10
+ # subtags MUST NOT include another extended language subtag in
11
+ # their 'Prefix'. That is, the second and third extended language
12
+ # subtag positions in a language tag are permanently reserved and
13
+ # tags that include those subtags in that position are, and will
14
+ # always remain, invalid.
15
+ #++
16
+
17
+ LANGUAGE = "[a-z]{2,3}(?:-[a-z]{3})?|[a-z]{4,8}"
18
+ LOOSE_LANGUAGE = "[a-z]{2,3}(?:-[a-z]{3}){0,3}|[a-z]{4,8}"
19
+ SCRIPT = "[a-z]{4}"
20
+ REGION = "[a-z]{2}|\\d{3}"
21
+ VARIANT = "[a-z\\d]{5,8}|\\d[a-z\\d]{3}"
22
+ VARIANT_SEQUENCE = "(?:-[a-z\\d]{5,8}|-\\d[a-z\\d]{3})"
23
+ SINGLETON = "[a-wy-z\\d]"
24
+ EXTENSION_SEQUENCE = "(?:-#{SINGLETON}(?:-[a-z\\d]{2,8})+)"
25
+ PRIVATEUSE = "x(?:-[a-z\\d]{1,8})+"
26
+
27
+ end
28
+ end
29
+ end
30
+
31
+ # EOF
@@ -0,0 +1,34 @@
1
+ require 'lang/tag'
2
+
3
+ module Lang #:nodoc:
4
+ module Tag
5
+
6
+ def self.Privateuse(thing)
7
+ return thing if Privateuse === thing
8
+ Privateuse.new(thing)
9
+ end
10
+
11
+ # Handles 'privateuse' registrations.
12
+ #
13
+ class Privateuse < Composition
14
+
15
+ def initialize(thing)
16
+ raise TypeError, "Can't convert #{thing.class} into String" unless thing.respond_to?(:to_str)
17
+ sequence = thing.to_str
18
+ unless Lang::Tag.privateuse?(sequence)
19
+ raise ArgumentError, "#{sequence.inspect} is not a privateuse language tag"
20
+ end
21
+ @sequence = sequence
22
+ end
23
+
24
+ def nicecase!
25
+ @sequence.downcase!
26
+ nil
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+
34
+ # EOF
@@ -0,0 +1,5 @@
1
+ module Lang #:nodoc:
2
+ VERSION = "0.1.0.pre".freeze
3
+ end
4
+
5
+ # EOF
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lang
3
+ version: !ruby/object:Gem::Version
4
+ hash: 961915980
5
+ prerelease: true
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ - pre
11
+ version: 0.1.0.pre
12
+ platform: ruby
13
+ authors:
14
+ - SSDany
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-09-06 00:00:00 +04:00
20
+ default_executable: lang
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rspec
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 31
31
+ segments:
32
+ - 1
33
+ - 2
34
+ - 0
35
+ version: 1.2.0
36
+ type: :development
37
+ version_requirements: *id001
38
+ description: |
39
+ Language tags implementation.
40
+ Features: basic and extended filtering (RFC 4647), canonicalization (using IANA language subtag registry).
41
+
42
+ email: inadsence@gmail.com
43
+ executables:
44
+ - lang
45
+ extensions: []
46
+
47
+ extra_rdoc_files:
48
+ - README.rdoc
49
+ files:
50
+ - README.rdoc
51
+ - lib/lang/subtags/entry.rb
52
+ - lib/lang/subtags/extlang.rb
53
+ - lib/lang/subtags/grandfathered.rb
54
+ - lib/lang/subtags/language.rb
55
+ - lib/lang/subtags/redundant.rb
56
+ - lib/lang/subtags/region.rb
57
+ - lib/lang/subtags/script.rb
58
+ - lib/lang/subtags/variant.rb
59
+ - lib/lang/subtags.rb
60
+ - lib/lang/tag/canonicalization.rb
61
+ - lib/lang/tag/composition.rb
62
+ - lib/lang/tag/filtering.rb
63
+ - lib/lang/tag/grandfathered.rb
64
+ - lib/lang/tag/langtag.rb
65
+ - lib/lang/tag/lookup.rb
66
+ - lib/lang/tag/pattern.rb
67
+ - lib/lang/tag/privateuse.rb
68
+ - lib/lang/tag.rb
69
+ - lib/lang/version.rb
70
+ - bin/lang
71
+ has_rdoc: true
72
+ homepage: http://github.com/SSDany/lang
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">"
93
+ - !ruby/object:Gem::Version
94
+ hash: 25
95
+ segments:
96
+ - 1
97
+ - 3
98
+ - 1
99
+ version: 1.3.1
100
+ requirements: []
101
+
102
+ rubyforge_project: lang
103
+ rubygems_version: 1.3.7
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Language tags implementation.
107
+ test_files: []
108
+