i18n-inflector 2.5.1 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/ChangeLog CHANGED
@@ -1,3 +1,83 @@
1
+ commit fd7508c5bd759e071feae8180b98ed9bf6c2931f
2
+ Author: Paweł Wilk <siefca@gnu.org>
3
+ Date: Sun Jul 10 03:16:21 2011 +0200
4
+
5
+ Release 2.6.1
6
+
7
+ commit 613cf034568c536b2dc0edc2d0cf0e80f95afe6a
8
+ Author: Paweł Wilk <siefca@gnu.org>
9
+ Date: Sat Jul 9 18:58:06 2011 +0200
10
+
11
+ Added @inflected_locales_cache that speeds up reporting of locales that support inflection
12
+
13
+ commit 950e6b8589f2d8893d30e1b892c8ed0fa1e26a78
14
+ Author: Paweł Wilk <siefca@gnu.org>
15
+ Date: Sat Jul 9 02:42:14 2011 +0200
16
+
17
+ Gem dependencies updated.
18
+
19
+ commit cd549b15580aff33d212e92870b16942b6cf8f55
20
+ Author: Paweł Wilk <siefca@gnu.org>
21
+ Date: Fri Jul 8 16:30:01 2011 +0200
22
+
23
+ Handling methods and Proc objects to obtain inflection options seriously improved
24
+
25
+ - added cache for inflection options that keeps them between calls to interpolate_core.
26
+
27
+ commit 5858b52225759e9760ec2301671cf78e64d02f33
28
+ Author: Paweł Wilk <siefca@gnu.org>
29
+ Date: Sat Apr 30 18:47:04 2011 +0200
30
+
31
+ Lazy operations optimized a bit
32
+
33
+ commit ee37910a2419afb9710ff0f1472634b29be7f0d8
34
+ Author: Paweł Wilk <siefca@gnu.org>
35
+ Date: Sat Apr 30 18:46:23 2011 +0200
36
+
37
+ Fixed documentation links
38
+
39
+ commit e6b753ac280b14a7c32de2bab3dd9540d72cde72
40
+ Author: Paweł Wilk <siefca@gnu.org>
41
+ Date: Mon Mar 7 00:45:23 2011 +0100
42
+
43
+ Release 2.6.0
44
+
45
+ commit a949e5aad5a2bed695fc3e00f129dd56dda73daa
46
+ Author: Paweł Wilk <siefca@gnu.org>
47
+ Date: Sun Mar 6 23:41:32 2011 +0100
48
+
49
+ Engine initialization improved
50
+
51
+ commit af4ea17f1961dd54bd600d789c33187af9cc9d69
52
+ Author: Paweł Wilk <siefca@gnu.org>
53
+ Date: Sun Mar 6 23:36:15 2011 +0100
54
+
55
+ Added union operators to some arrays
56
+
57
+ commit e21b810282bd98e3e49030267382d2a4358ab285
58
+ Author: Paweł Wilk <siefca@gnu.org>
59
+ Date: Sun Mar 6 23:35:14 2011 +0100
60
+
61
+ Added lazy iteration interfaces to API and core classes
62
+
63
+ commit 8f480682b1f5c418c31cbbdfb3b5f1b3d3549713
64
+ Author: Paweł Wilk <siefca@gnu.org>
65
+ Date: Sat Mar 5 14:32:52 2011 +0100
66
+
67
+ Added a note about YAML parsing issues.
68
+
69
+ commit 9fb6687d1e7ae003fb653d2af426e522f6d9f399
70
+ Author: Paweł Wilk <siefca@gnu.org>
71
+ Date: Sat Mar 5 14:32:25 2011 +0100
72
+
73
+ Fixed static gemspec
74
+
75
+ commit 6ccbc782f089c603afeff48a7b7492011b486dfe
76
+ Author: Paweł Wilk <siefca@gnu.org>
77
+ Date: Sat Mar 5 14:31:42 2011 +0100
78
+
79
+ Optimized contatenations if Strings
80
+
1
81
  commit b62605859be67525a5c2f902a387fa92f0adebb8
2
82
  Author: Paweł Wilk <siefca@gnu.org>
3
83
  Date: Fri Feb 25 19:33:24 2011 +0100
data/Gemfile CHANGED
@@ -1,14 +1,17 @@
1
1
  # -*- ruby -*-
2
2
 
3
+ # DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
4
+
3
5
  source :gemcutter
4
6
 
5
7
  gem "i18n", ">=0.4.1"
6
8
 
7
9
  gem "hoe-yard", ">=0.1.2", :group => [:development, :test]
8
- gem "test_declarative", ">=0.0.4", :group => [:development, :test]
9
- gem "yard", ">=0.6.4", :group => [:development, :test]
10
- gem "bundler", ">=1.0.7", :group => [:development, :test]
11
- gem "hoe-bundler", ">=1.0.0", :group => [:development, :test]
12
- gem "hoe", ">=2.8.0", :group => [:development, :test]
10
+ gem "test_declarative", ">=0.0.5", :group => [:development, :test]
11
+ gem "yard", ">=0.7.2", :group => [:development, :test]
12
+ gem "rdoc", ">=3.8.0", :group => [:development, :test]
13
+ gem "bundler", ">=1.0.15", :group => [:development, :test]
14
+ gem "hoe-bundler", ">=1.1.0", :group => [:development, :test]
15
+ gem "hoe", "~>2.10", :group => [:development, :test]
13
16
 
14
17
  # vim: syntax=ruby
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ hoe (2.10.0)
5
+ rake (~> 0.8)
6
+ hoe-bundler (1.1.0)
7
+ hoe (>= 2.2.0)
8
+ hoe-yard (0.1.2)
9
+ yard (>= 0.2.3.1)
10
+ i18n (0.6.0)
11
+ rake (0.9.2)
12
+ rdoc (3.8)
13
+ test_declarative (0.0.5)
14
+ yard (0.7.2)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (>= 1.0.15)
21
+ hoe (~> 2.10)
22
+ hoe-bundler (>= 1.1.0)
23
+ hoe-yard (>= 0.1.2)
24
+ i18n (>= 0.4.1)
25
+ rdoc (>= 3.8.0)
26
+ test_declarative (>= 0.0.5)
27
+ yard (>= 0.7.2)
data/Manifest.txt CHANGED
@@ -1,12 +1,14 @@
1
1
  .yardopts
2
2
  ChangeLog
3
3
  Gemfile
4
+ Gemfile.lock
4
5
  LGPL-LICENSE
5
6
  Manifest.txt
6
7
  README.rdoc
7
8
  Rakefile
8
9
  ci/i18n-inflector.gemspec
9
10
  ci/i18nv4-Gemfile
11
+ ci/i18nv4-Gemfile.lock
10
12
  docs/COPYING
11
13
  docs/EXAMPLES
12
14
  docs/HISTORY
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Simple Inflector for I18n
2
2
 
3
- <b>i18n-inflector version <tt>2.5</tt></b> (<b><tt>Akasha</tt></b>)
3
+ <b>i18n-inflector version <tt>2.6</tt></b> (<b><tt>Madonna</tt></b>)
4
4
 
5
5
 
6
6
 
@@ -62,6 +62,32 @@ Example translation data:
62
62
  @prefix: "Dear "
63
63
  @suffix: "!"
64
64
  @free: "All"
65
+
66
+ === Note about YAML parsing
67
+
68
+ The example above is not compatible with Psych parser, which is used
69
+ by Rails 3. There are two ways to solve that problem.
70
+
71
+ First is to change a YAML file and replace any value that has
72
+ special meaning with a symbol:
73
+
74
+ en:
75
+ i18n:
76
+ inflections:
77
+ gender:
78
+ f: "female"
79
+ m: "male"
80
+ n: "neuter"
81
+ female: :@f
82
+ male: :@m
83
+ default: :n
84
+
85
+ Second way is to use other parser by adding to +config/boot.rb+:
86
+
87
+ require 'yaml'
88
+ YAML::ENGINE.yamler = 'syck'
89
+
90
+ == New features
65
91
 
66
92
  From version 2.1.0 the Inflector supports so called named patterns,
67
93
  which can be used if there is a need to be strict and/or to
data/Rakefile CHANGED
@@ -20,6 +20,14 @@ task :default do
20
20
  Rake::Task[:testv4].invoke
21
21
  end
22
22
 
23
+ # Update Gemfile for I18n in version 4
24
+ task :gemfilev4 do
25
+ gemprev = ENV['BUNDLE_GEMFILE']
26
+ ENV['BUNDLE_GEMFILE'] = 'ci/i18nv4-Gemfile'
27
+ `rake bundler:gemfile`
28
+ ENV['BUNDLE_GEMFILE'] = gemprev
29
+ end
30
+
23
31
  # Tests for I18n in version 4
24
32
  task :testv4 do
25
33
  gemprev = ENV['BUNDLE_GEMFILE']
@@ -56,14 +64,16 @@ Hoe.spec 'i18n-inflector' do
56
64
  self.history_file = 'docs/HISTORY'
57
65
 
58
66
  extra_deps << ['i18n', '>= 0.4.1']
59
- extra_dev_deps << ['test_declarative', '>= 0.0.4'] <<
60
- ['yard', '>= 0.6.4'] <<
61
- ['bundler', '>= 1.0.10'] <<
62
- ['hoe-bundler', '>= 1.0.0']
67
+ extra_dev_deps << ['test_declarative', '>= 0.0.5'] <<
68
+ ['yard', '>= 0.7.2'] <<
69
+ ['rdoc', '>= 3.8.0'] <<
70
+ ['bundler', '>= 1.0.15'] <<
71
+ ['hoe-bundler', '>= 1.1.0']
63
72
 
64
73
  unless extra_dev_deps.flatten.include?('hoe-yard')
65
74
  extra_dev_deps << ['hoe-yard', '>= 0.1.2']
66
75
  end
76
+
67
77
  end
68
78
 
69
79
  task 'Manifest.txt' do
@@ -2,6 +2,7 @@
2
2
 
3
3
  lib = File.expand_path('../../lib/', __FILE__)
4
4
  $:.unshift lib unless $:.include?(lib)
5
+
5
6
  require 'i18n-inflector/version'
6
7
 
7
8
  Gem::Specification.new do |s|
@@ -13,9 +14,9 @@ Gem::Specification.new do |s|
13
14
  s.summary = I18n::Inflector::SUMMARY
14
15
  s.description = I18n::Inflector::DESCRIPTION
15
16
 
16
- s.files = Dir.glob("{ci,lib,spec,docs}/**/**") + %w(Gemfile .rspec .yardopts README.rdoc LGPL-LICENSE ChangeLog Manifest.txt)
17
+ s.files = Dir.glob("{ci,lib,spec,docs}/**/**") + %w(Gemfile .yardopts README.rdoc LGPL-LICENSE ChangeLog Manifest.txt)
17
18
  s.extra_rdoc_files = ["README.rdoc", "docs/USAGE", "docs/EXAMPLES", "docs/TODO", "docs/HISTORY", "docs/LEGAL", "docs/LGPL", "docs/COPYING"]
18
- s.rdoc_options = ["--main", "README.rdoc"]
19
+ s.rdoc_options = [ "--charset=UTF-8", "--main", "README.rdoc"]
19
20
  s.platform = Gem::Platform::RUBY
20
21
  s.require_path = 'lib'
21
22
  s.rubyforge_project = '[none]'
@@ -23,11 +24,11 @@ Gem::Specification.new do |s|
23
24
  s.specification_version = 3
24
25
 
25
26
  s.add_dependency 'i18n', '>= 0.4.1'
26
- s.add_development_dependency 'test_declarative', '>= 0.0.4'
27
+ s.add_development_dependency 'test_declarative', '>= 0.0.5'
27
28
  s.add_development_dependency 'rspec', '>= 2.3.0'
28
- s.add_development_dependency 'yard', '>= 1.0.7'
29
- s.add_development_dependency 'yard', '>= 1.0.10'
29
+ s.add_development_dependency 'yard', '>= 0.7.2'
30
+ s.add_development_dependency 'bundler', '>= 1.0.15'
30
31
  s.add_development_dependency 'hoe-yard', '>= 0.1.2'
31
- s.add_development_dependency 'hoe-bundler', '>= 1.0.0'
32
+ s.add_development_dependency 'hoe-bundler', '>= 1.1.0'
32
33
 
33
34
  end
data/ci/i18nv4-Gemfile CHANGED
@@ -10,6 +10,6 @@ gem "yard", ">=0.6.4", :group => [:development, :test]
10
10
  gem "bundler", ">=1.0.7", :group => [:development, :test]
11
11
  gem "hoe-bundler", ">=1.0.0", :group => [:development, :test]
12
12
  gem "hoe-yard", ">=0.1.2", :group => [:development, :test]
13
- gem "hoe", ">=2.8.0", :group => [:development, :test]
13
+ gem "hoe", ">=2.10.0", :group => [:development, :test]
14
14
 
15
15
  # vim: syntax=ruby
@@ -0,0 +1,25 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ hoe (2.10.0)
5
+ rake (~> 0.8)
6
+ hoe-bundler (1.1.0)
7
+ hoe (>= 2.2.0)
8
+ hoe-yard (0.1.2)
9
+ yard (>= 0.2.3.1)
10
+ i18n (0.4.2)
11
+ rake (0.9.2)
12
+ test_declarative (0.0.5)
13
+ yard (0.7.2)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (>= 1.0.7)
20
+ hoe (>= 2.10.0)
21
+ hoe-bundler (>= 1.0.0)
22
+ hoe-yard (>= 0.1.2)
23
+ i18n (>= 0.4.1, < 0.5.0)
24
+ test_declarative (>= 0.0.4)
25
+ yard (>= 0.6.4)
data/docs/HISTORY CHANGED
@@ -1,3 +1,25 @@
1
+ === 2.6.1 / 2011-07-10
2
+
3
+ * major enhancements
4
+
5
+ * Handling of methods and Proc objects used to obtain inflection options improved by caching
6
+ * Added caching for methods reporting locales that support inflection
7
+ * Lazy operations optimized
8
+
9
+ * minor enhancements
10
+
11
+ * Fixed documentation links
12
+ * Dependencies updated
13
+
14
+ === 2.6.0 / 2011-03-08
15
+
16
+ * minor enhancements
17
+
18
+ * Strings concatenation optimized
19
+ * API methods simplified
20
+ * Added lazy iteration methods to I18n::Inflector::InflectionData and I18n::Inflector::InflectionData_Strict
21
+ * Added lazy iteration methods to I18n::Inflector::API and I18n::Inflector::API_Strict
22
+
1
23
  === 2.5.1 / 2011-02-25
2
24
 
3
25
  * minor enhancements
data/docs/TODO CHANGED
@@ -1,7 +1,8 @@
1
1
  == Near future
2
2
 
3
+
4
+
3
5
  == Distant future
4
6
 
5
7
  * split interpolate_core and make it more reusable by raw data (e.g. pattern content)
6
8
  * allow different descriptions for aliases pointing to the same token, e.g.: now: @present ="description"
7
-
data/docs/USAGE CHANGED
@@ -64,6 +64,34 @@ Elements in the example above are:
64
64
  * <tt>@f</tt>, <tt>@m</tt>: pointers to real tokens
65
65
  * +default+: default token for a kind +gender+
66
66
 
67
+ === Note about YAML parsing
68
+
69
+ The example above is not compatible with Psych parser, which is used
70
+ by Rails 3. There are two ways to solve that problem.
71
+
72
+ First is to make a change in a YAML file and replace any value that has
73
+ special meaning with a symbol:
74
+
75
+ en:
76
+ i18n:
77
+ inflections:
78
+ gender:
79
+ f: "female"
80
+ m: "male"
81
+ n: "neuter"
82
+ female: :@f
83
+ male: :@m
84
+ default: :n
85
+
86
+ Second way is to use other parser by adding to +config/boot.rb+:
87
+
88
+ require 'yaml'
89
+ YAML::ENGINE.yamler = 'syck'
90
+
91
+ Note that all the examples in this documentation use the less strict format.
92
+ If you will encounter any parsing problems in your application then change
93
+ all problematic inflection values in YAML files into symbols.
94
+
67
95
  === Kind
68
96
  Note the fourth scope selector in the example above (+gender+). It's called
69
97
  the *kind* and contains *tokens*. We have the kind
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Author:: Paweł Wilk (mailto:pw@gnu.org)
4
4
  # Copyright:: (c) 2011 by Paweł Wilk
5
- # License:: This program is licensed under the terms of {file:docs/LGPL GNU Lesser General Public License} or {file:COPYING Ruby License}.
5
+ # License:: This program is licensed under the terms of {file:docs/LGPL GNU Lesser General Public License} or {file:docs/COPYING Ruby License}.
6
6
  #
7
7
  # This file contains {I18n::Inflector::API} class,
8
8
  # which is public API for I18n Inflector.
@@ -40,7 +40,7 @@ module I18n
40
40
  # @see I18n::Inflector::API_Strict The API_Strict class
41
41
  # for accessing inflection data for named
42
42
  # patterns (strict kinds).
43
- # @see file:EXAMPLES The examples of real-life usage.
43
+ # @see file:docs/EXAMPLES The examples of real-life usage.
44
44
  # @api public
45
45
  class API < API_Strict
46
46
 
@@ -178,7 +178,7 @@ module I18n
178
178
  # Gets locales which have configured inflection support.
179
179
  #
180
180
  # @api public
181
- # @note That method uses information from regular and strict kinds.
181
+ # @note This method uses information from both regular and strict kinds.
182
182
  # @return [Array<Symbol>] the array containing locales that support inflection
183
183
  #
184
184
  # @overload inflected_locales
@@ -194,10 +194,34 @@ module I18n
194
194
  if kind.to_s[0..0] == Markers::STRICT_KIND
195
195
  strict.inflected_locales(kind.to_s[1..-1])
196
196
  else
197
- (super + strict.inflected_locales(kind)).uniq
197
+ kind = kind.to_s.empty? ? nil : kind.to_sym
198
+ r = ( @inflected_locales_cache[kind] ||= super(kind).uniq )
199
+ r.nil? ? r : r.dup
198
200
  end
199
201
  end
200
202
 
203
+ # Iterates through locales which have configured inflection support.
204
+ #
205
+ # @api public
206
+ # @note This method uses information from both regular and strict kinds.
207
+ # The locale identifiers may be duplicated!
208
+ # @return [LazyArrayEnumerator] the lazy enumerator
209
+ # @yield [locale] optional block in which each kind will be yielded
210
+ # @yieldparam [Symbol] locale the inflected locale identifier
211
+ # @yieldreturn [LazyArrayEnumerator] the lazy enumerator
212
+ # @overload each_inflected_locale
213
+ # Iterates through locales which have configured inflection support.
214
+ # @return [LazyArrayEnumerator] the lazy enumerator
215
+ # @overload each_inflected_locale(kind)
216
+ # Iterates through locales which have configured inflection support for the given +kind+.
217
+ # @param [Symbol] kind the identifier of a kind
218
+ # @return [LazyArrayEnumerator] the lazy enumerator
219
+ def each_inflected_locale(kind=nil, &block)
220
+ super + strict.inflected_locales(kind)
221
+ end
222
+ alias_method :each_locale, :each_inflected_locale
223
+ alias_method :each_supported_locale, :each_inflected_locale
224
+
201
225
  # Tests if a kind exists.
202
226
  #
203
227
  # @api public
@@ -480,159 +504,139 @@ module I18n
480
504
  data_safe(locale).get_kind(token.to_sym, kind)
481
505
  end
482
506
 
483
- # Gets available inflection tokens and their descriptions.
507
+ # Iterates through available inflection tokens and their descriptions.
484
508
  #
485
509
  # @api public
486
510
  # @note By default it uses regular kinds database, not strict kinds.
487
511
  # @raise [I18n::InvalidLocale] if there is no proper locale name
488
- # @return [Hash] the hash containing available inflection tokens and descriptions
512
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
513
+ # @yield [token, description] optional block in which each token will be yielded
514
+ # @yieldparam [Symbol] token a token
515
+ # @yieldparam [String] description a description string for a token
516
+ # @yieldreturn [LazyHashEnumerator] the lazy enumerator
489
517
  # @note You cannot deduce where aliases are pointing to, since the information
490
518
  # about a target is replaced by the description. To get targets use the
491
519
  # {#raw_tokens} method. To simply list aliases and their targets use
492
520
  # the {#aliases} method.
493
- # @overload tokens
494
- # Gets available inflection tokens and their descriptions.
495
- # @return [Hash] the hash containing available inflection tokens as keys
496
- # and their descriptions as values, including aliases,
497
- # for all kinds.
498
- # @overload tokens(kind)
499
- # Gets available inflection tokens and their descriptions for some +kind+.
521
+ # @overload each_token
522
+ # Iterates through available inflection tokens and their descriptions.
523
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
524
+ # @overload each_token(kind)
525
+ # Iterates through available inflection tokens and their descriptions for some +kind+.
500
526
  # @note If +kind+ begins with the +@+ symbol then the variant of this method
501
- # operating on strict kinds will be called ({I18n::Inflector::API_Strict#tokens})
527
+ # operating on strict kinds will be called ({I18n::Inflector::API_Strict#each_token})
502
528
  # @param [Symbol,String] kind the kind of inflection tokens to be returned
503
- # @return [Hash] the hash containing available inflection tokens as keys
504
- # and their descriptions as values, including aliases, for current locale.
505
- # @overload tokens(kind, locale)
506
- # Gets available inflection tokens and their descriptions for some +kind+ and +locale+.
529
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
530
+ # @overload each_token(kind, locale)
531
+ # Iterates through available inflection tokens and their descriptions for some +kind+ and +locale+.
507
532
  # @note If +kind+ begins with the +@+ symbol then the variant of this method
508
- # operating on strict kinds will be called ({I18n::Inflector::API_Strict#tokens})
533
+ # operating on strict kinds will be called ({I18n::Inflector::API_Strict#each_token})
509
534
  # @param [Symbol,String] kind the kind of inflection tokens to be returned
510
535
  # @param [Symbol] locale the locale to use
511
- # @return [Hash] the hash containing available inflection tokens as keys
512
- # and their descriptions as values, including aliases, for current locale
513
- def tokens(kind=nil, locale=nil)
514
- unless kind.nil?
515
- kind = kind.to_s
516
- return {} if kind.empty?
517
- if kind[0..0] == Markers::STRICT_KIND
518
- return strict.tokens(kind[1..-1], locale)
519
- end
520
- kind = kind.to_sym
536
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
537
+ def each_token(kind=nil, locale=nil)
538
+ if kind.to_s[0..0] == Markers::STRICT_KIND
539
+ return strict.each_token(kind.to_s[1..-1], locale)
521
540
  end
522
- data_safe(locale).get_tokens(kind)
541
+ super
523
542
  end
524
543
 
525
- # Gets available inflection tokens and their values.
544
+ # Iterates through available inflection tokens and their values.
526
545
  #
527
546
  # @api public
528
- # @return [Hash] the hash containing available inflection tokens and descriptions (or alias pointers)
547
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description|target</tt>)
548
+ # @yield [token, value] optional block in which each token will be yielded
549
+ # @yieldparam [Symbol] token a token
550
+ # @yieldparam [Symbol, String] value a description string for a token or a target (if alias)
551
+ # @yieldreturn [LazyHashEnumerator] the lazy enumerator
529
552
  # @raise [I18n::InvalidLocale] if there is no proper locale name
530
553
  # @note You may deduce whether the returned values are aliases or true tokens
531
554
  # by testing if a value is a type of Symbol or String.
532
- # @overload tokens_raw
533
- # Gets available inflection tokens and their values for regular kinds.
534
- # @return [Hash] the hash containing available inflection tokens as keys
535
- # and their descriptions as values. In case of aliases the returned
536
- # values are Symbols
537
- # @overload tokens_raw(kind)
538
- # Gets available inflection tokens and their values for the given +kind+.
555
+ # @overload each_token_raw
556
+ # Iterates through available inflection tokens and their values for regular kinds.
557
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description|target</tt>)
558
+ # @overload each_token_raw(kind)
559
+ # Iterates through available inflection tokens and their values for the given +kind+.
539
560
  # @note If +kind+ begins with the +@+ symbol then the variant of this method
540
- # operating on strict kinds will be called ({I18n::Inflector::API_Strict#tokens_raw})
561
+ # operating on strict kinds will be called ({I18n::Inflector::API_Strict#each_token_raw})
541
562
  # @param [Symbol,String] kind the kind of inflection tokens to be returned
542
- # @return [Hash] the hash containing available inflection tokens as keys
543
- # and their descriptions as values. In case of aliases the returned
544
- # values are Symbols
545
- # @overload tokens_raw(kind, locale)
546
- # Gets available inflection tokens and their values for the given +kind+ and +locale+.
563
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description|target</tt>)
564
+ # @overload each_token_raw(kind, locale)
565
+ # Iterates through available inflection tokens and their values for the given +kind+ and +locale+.
547
566
  # @note If +kind+ begins with the +@+ symbol then the variant of this method
548
- # operating on strict kinds will be called ({I18n::Inflector::API_Strict#tokens_raw})
567
+ # operating on strict kinds will be called ({I18n::Inflector::API_Strict#each_token_raw})
549
568
  # @param [Symbol,String] kind the kind of inflection tokens to be returned
550
569
  # @param [Symbol] locale the locale to use
551
- # @return [Hash] the hash containing available inflection tokens as keys
552
- # and their descriptions as values. In case of aliases the returned
553
- # values are Symbols
554
- def tokens_raw(kind=nil, locale=nil)
555
- unless kind.nil?
556
- kind = kind.to_s
557
- return {} if kind.empty?
558
- if kind[0..0] == Markers::STRICT_KIND
559
- return strict.tokens_raw(kind[1..-1], locale)
560
- end
561
- kind = kind.to_sym
570
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description|target</tt>)
571
+ def each_token_raw(kind=nil, locale=nil)
572
+ if kind.to_s[0..0] == Markers::STRICT_KIND
573
+ return strict.each_token_raw(kind.to_s[1..-1], locale)
562
574
  end
563
- data_safe(locale).get_raw_tokens(kind)
575
+ super
564
576
  end
565
- alias_method :raw_tokens, :tokens_raw
577
+ alias_method :each_raw_token, :each_token_raw
566
578
 
567
- # Gets true inflection tokens and their values.
579
+ # Iterates through true inflection tokens and their values.
568
580
  #
569
581
  # @api public
570
- # @return [Hash] the hash containing available inflection tokens and descriptions
582
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
583
+ # @yield [token, description] optional block in which each token will be yielded
584
+ # @yieldparam [Symbol] token a token
585
+ # @yieldparam [String] description a description string for a token
586
+ # @yieldreturn [LazyHashEnumerator] the lazy enumerator
571
587
  # @raise [I18n::InvalidLocale] if there is no proper locale name
572
588
  # @note It returns only true tokens, not aliases.
573
- # @overload tokens_true
574
- # Gets true inflection tokens and their values for regular kinds.
575
- # @return [Hash] the hash containing available inflection tokens as keys
576
- # and their descriptions as values
577
- # @overload tokens_true(kind)
578
- # Gets true inflection tokens and their values for the given +kind+.
589
+ # @overload each_token_true
590
+ # Iterates through true inflection tokens and their values for regular kinds.
591
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
592
+ # @overload each_token_true(kind)
593
+ # Iterates through true inflection tokens and their values for the given +kind+.
579
594
  # @note If +kind+ begins with the +@+ symbol then the variant of this method
580
- # operating on strict kinds will be called ({I18n::Inflector::API_Strict#tokens_true})
595
+ # operating on strict kinds will be called ({I18n::Inflector::API_Strict#each_token_true})
581
596
  # @param [Symbol,String] kind the kind of inflection tokens to be returned
582
- # @return [Hash] the hash containing available inflection tokens as keys
583
- # and their descriptions as values
584
- # @overload tokens_true(kind, locale)
585
- # Gets true inflection tokens and their values for the given +kind+ and +value+.
597
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
598
+ # @overload each_token_true(kind, locale)
599
+ # Iterates through true inflection tokens and their values for the given +kind+ and +value+.
586
600
  # @note If +kind+ begins with the +@+ symbol then the variant of this method
587
- # operating on strict kinds will be called ({I18n::Inflector::API_Strict#tokens_true})
601
+ # operating on strict kinds will be called ({I18n::Inflector::API_Strict#each_token_true})
588
602
  # @param [Symbol,String] kind the kind of inflection tokens to be returned
589
603
  # @param [Symbol] locale the locale to use
590
- # @return [Hash] the hash containing available inflection tokens as keys
591
- # and their descriptions as values
592
- def tokens_true(kind=nil, locale=nil)
593
- unless kind.nil?
594
- kind = kind.to_s
595
- return {} if kind.empty?
596
- if kind[0..0] == Markers::STRICT_KIND
597
- return strict.tokens_true(kind[1..-1], locale)
598
- end
599
- kind = kind.to_sym
604
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => description</tt>)
605
+ def each_token_true(kind=nil, locale=nil, &block)
606
+ if kind.to_s[0..0] == Markers::STRICT_KIND
607
+ return strict.each_token_true(kind.to_s[1..-1], locale, &block)
600
608
  end
601
- data_safe(locale).get_true_tokens(kind)
609
+ super
602
610
  end
603
- alias_method :true_tokens, :tokens_true
611
+ alias_method :each_true_token, :each_token_true
604
612
 
605
- # Gets inflection aliases and their pointers.
613
+ # Iterates through inflection aliases and their pointers.
606
614
  #
607
615
  # @api public
608
616
  # @raise [I18n::InvalidLocale] if there is no proper locale name
609
- # @return [Hash] the Hash containing available inflection aliases (<tt>alias => target</tt>)
610
- # @overload aliases
611
- # Gets inflection aliases and their pointers for regular kinds.
612
- # @return [Hash] the Hash containing available inflection aliases
613
- # @overload aliases(kind)
614
- # Gets inflection aliases and their pointers for the given +kind+.
617
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => target</tt>)
618
+ # @yield [alias, target] optional block in which each alias will be yielded
619
+ # @yieldparam [Symbol] alias an alias
620
+ # @yieldparam [Symbol] target a name of the target token
621
+ # @yieldreturn [LazyHashEnumerator] the lazy enumerator
622
+ # @overload each_alias(kind)
623
+ # Iterates through inflection aliases (and their pointers) of the given +kind+ and the current locale.
615
624
  # @note If +kind+ begins with the +@+ symbol then the variant of this method
616
- # operating on strict kinds will be called ({I18n::Inflector::API_Strict#aliases})
625
+ # operating on strict kinds will be called ({I18n::Inflector::API_Strict#each_alias})
617
626
  # @param [Symbol,String] kind the kind of aliases to get
618
- # @return [Hash] the Hash containing available inflection aliases
619
- # @overload aliases(kind, locale)
620
- # Gets inflection aliases and their pointers for the given +kind+ and +locale+.
627
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => target</tt>)
628
+ # @overload each_alias(kind, locale)
629
+ # Iterates through inflection aliases (and their pointers) of the given +kind+ and +locale+.
621
630
  # @note If +kind+ begins with the +@+ symbol then the variant of this method
622
- # operating on strict kinds will be called ({I18n::Inflector::API_Strict#aliases})
631
+ # operating on strict kinds will be called ({I18n::Inflector::API_Strict#each_alias})
623
632
  # @param [Symbol,String] kind the kind of aliases to get
624
633
  # @param [Symbol] locale the locale to use
625
- # @return [Hash] the Hash containing available inflection aliases
626
- def aliases(kind=nil, locale=nil)
627
- unless kind.nil?
628
- kind = kind.to_s
629
- return nil if kind.empty?
630
- if kind[0..0] == Markers::STRICT_KIND
631
- return strict.aliases(kind[1..-1], locale)
632
- end
633
- kind = kind.to_sym
634
+ # @return [LazyHashEnumerator] the lazy enumerator (<tt>token => target</tt>)
635
+ def each_alias(kind=nil, locale=nil, &block)
636
+ if kind.to_s[0..0] == Markers::STRICT_KIND
637
+ return strict.each_alias(kind.to_s[1..-1], locale, &block)
634
638
  end
635
- data_safe(locale).get_aliases(kind)
639
+ super
636
640
  end
637
641
 
638
642
  # Gets the description of the given inflection token.