cldr-plurals 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rspec'
4
+ require 'pry-nav'
5
+ require 'cldr-plurals'
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :rr
9
+ end
10
+
11
+ def each_rule
12
+ samples.each_pair do |locales, rules|
13
+ rules.each do |rule|
14
+ next if rule[:text].empty? # @TODO handle this case
15
+ tokens = CldrPlurals::Compiler::Tokenizer.tokenize(rule[:text])
16
+ rule_ast = CldrPlurals::Compiler::Parser.new(tokens).parse
17
+ yield locales, rule_ast, rule[:samples]
18
+ end
19
+ end
20
+ end
21
+
22
+ def each_rule_list
23
+ samples.each_pair do |locales, rules|
24
+ rule_list = CldrPlurals::Compiler::RuleList.new(locales)
25
+ samples = {}
26
+
27
+ rules.each do |rule|
28
+ next if rule[:text].empty? # @TODO: handle this case
29
+ rule_list.add_rule(rule[:name], rule[:text])
30
+ samples[rule[:name]] = rule[:samples]
31
+ end
32
+
33
+ samples_per_name = samples.each_with_object({}) do |(name, samples), ret|
34
+ ret[name] = samples.flat_map do |sample_info|
35
+ sample_info[:samples]
36
+ end
37
+ end
38
+
39
+ yield rule_list, samples_per_name
40
+ end
41
+ end
42
+
43
+ def samples
44
+ YAML.load_file(samples_file)
45
+ end
46
+
47
+ def samples_file
48
+ File.join(File.expand_path(File.dirname(__FILE__)), 'samples.yml')
49
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cldr-plurals
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cameron Dutro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Tokenizes and parses CLDR plural rules and provides a mechanism for emitting
14
+ them as source code
15
+ email:
16
+ - camertron@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/cldr-plurals/compiler/emitter.rb
22
+ - lib/cldr-plurals/compiler/nodes.rb
23
+ - lib/cldr-plurals/compiler/parser.rb
24
+ - lib/cldr-plurals/compiler/tokenizer.rb
25
+ - lib/cldr-plurals/compiler.rb
26
+ - lib/cldr-plurals/javascript_emitter.rb
27
+ - lib/cldr-plurals/ruby_emitter.rb
28
+ - lib/cldr-plurals/version.rb
29
+ - lib/cldr-plurals.rb
30
+ - spec/javascript_sample_spec.rb
31
+ - spec/ruby_sample_spec.rb
32
+ - spec/samples.yml
33
+ - spec/spec_helper.rb
34
+ - Gemfile
35
+ - History.txt
36
+ - README.md
37
+ - Rakefile
38
+ - cldr-plurals.gemspec
39
+ homepage: http://github.com/camertron
40
+ licenses: []
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.0.14
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Tokenizes and parses CLDR plural rules and provides a mechanism for emitting
62
+ them as source code
63
+ test_files: []