ruby-cldr 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Gemfile.lock +23 -0
- data/README.textile +9 -6
- data/VERSION +1 -1
- data/lib/cldr.rb +1 -1
- data/lib/cldr/data.rb +9 -29
- data/lib/cldr/download.rb +2 -2
- data/lib/cldr/export.rb +8 -2
- data/lib/cldr/export/code.rb +34 -0
- data/lib/cldr/export/code/numbers.rb +29 -0
- data/lib/cldr/export/data.rb +36 -0
- data/lib/cldr/export/data/base.rb +61 -0
- data/lib/cldr/export/data/calendars.rb +14 -0
- data/lib/cldr/export/data/calendars/gregorian.rb +142 -0
- data/lib/cldr/export/data/currencies.rb +28 -0
- data/lib/cldr/export/data/delimiters.rb +29 -0
- data/lib/cldr/export/data/languages.rb +19 -0
- data/lib/cldr/export/data/numbers.rb +67 -0
- data/lib/cldr/export/data/plurals.rb +41 -0
- data/lib/cldr/{data → export/data}/plurals/cldr_grammar.treetop +0 -0
- data/lib/cldr/export/data/plurals/grammar.rb +538 -0
- data/lib/cldr/export/data/plurals/rules.rb +119 -0
- data/lib/cldr/export/data/territories.rb +19 -0
- data/lib/cldr/export/data/timezones.rb +27 -0
- data/lib/cldr/export/data/units.rb +29 -0
- data/lib/cldr/export/ruby.rb +1 -1
- data/lib/cldr/export/yaml.rb +1 -1
- data/lib/cldr/format.rb +1 -97
- data/lib/cldr/format/currency.rb +1 -1
- data/lib/cldr/format/date.rb +1 -1
- data/lib/cldr/format/datetime.rb +14 -18
- data/lib/cldr/format/datetime/base.rb +1 -1
- data/lib/cldr/format/decimal.rb +1 -1
- data/lib/cldr/format/decimal/base.rb +1 -1
- data/lib/cldr/format/decimal/fraction.rb +1 -1
- data/lib/cldr/format/decimal/integer.rb +1 -1
- data/lib/cldr/format/decimal/number.rb +1 -1
- data/lib/cldr/format/percent.rb +1 -1
- data/lib/cldr/format/time.rb +1 -1
- data/lib/cldr/thor.rb +3 -3
- data/test/all.rb +1 -1
- data/test/export/code/numbers_test.rb +11 -0
- data/test/{data → export/data}/all.rb +1 -1
- data/test/{data → export/data}/calendars_test.rb +18 -18
- data/test/{data → export/data}/currencies_test.rb +6 -6
- data/test/{data → export/data}/delimiters_test.rb +6 -6
- data/test/{data → export/data}/languages_test.rb +6 -6
- data/test/{data → export/data}/numbers_test.rb +8 -8
- data/test/export/data/plurals_test.rb +141 -0
- data/test/{data → export/data}/territories_test.rb +6 -6
- data/test/{data → export/data}/timezones_test.rb +6 -6
- data/test/{data → export/data}/units_test.rb +6 -6
- data/test/export_test.rb +8 -8
- data/test/{formats → format}/all.rb +1 -1
- data/test/format/currency_test.rb +0 -0
- data/test/format/date_test.rb +265 -0
- data/test/format/datetime_test.rb +18 -0
- data/test/{formats → format}/decimal/fraction_test.rb +4 -4
- data/test/{formats → format}/decimal/integer_test.rb +17 -17
- data/test/{formats → format}/decimal/number_test.rb +19 -19
- data/test/{formats → format}/decimal_test.rb +5 -5
- data/test/format/percent_test.rb +0 -0
- data/test/format/time_test.rb +195 -0
- data/test/test_autotest.rb +36 -0
- data/test/test_helper.rb +16 -1
- metadata +124 -114
- data/lib/cldr/data/base.rb +0 -66
- data/lib/cldr/data/calendars.rb +0 -12
- data/lib/cldr/data/calendars/gregorian.rb +0 -124
- data/lib/cldr/data/currencies.rb +0 -26
- data/lib/cldr/data/delimiters.rb +0 -21
- data/lib/cldr/data/languages.rb +0 -17
- data/lib/cldr/data/numbers.rb +0 -60
- data/lib/cldr/data/plurals.rb +0 -39
- data/lib/cldr/data/plurals/grammar.rb +0 -536
- data/lib/cldr/data/plurals/rules.rb +0 -113
- data/lib/cldr/data/territories.rb +0 -17
- data/lib/cldr/data/timezones.rb +0 -25
- data/lib/cldr/data/units.rb +0 -25
- data/test/data/plurals_test.rb +0 -132
- data/test/formats/datetime/all.rb +0 -3
- data/test/formats/datetime/date_test.rb +0 -31
- data/test/formats/datetime/datetime_test.rb +0 -18
- data/test/formats/datetime/day_test.rb +0 -41
- data/test/formats/datetime/hour_test.rb +0 -79
- data/test/formats/datetime/minute_test.rb +0 -25
- data/test/formats/datetime/month_test.rb +0 -76
- data/test/formats/datetime/period_test.rb +0 -20
- data/test/formats/datetime/quarter_test.rb +0 -118
- data/test/formats/datetime/second_test.rb +0 -80
- data/test/formats/datetime/time_test.rb +0 -33
- data/test/formats/datetime/timezone_test.rb +0 -23
- data/test/formats/datetime/year_test.rb +0 -57
- data/test/formats/format_test.rb +0 -66
- data/test/formats/rails_compat/all.rb +0 -3
- data/test/formats/rails_compat/format_integer_test.rb +0 -56
- data/test/formats/rails_compat/format_number_test.rb +0 -134
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
i18n (0.6.0)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
nokogiri (1.5.0)
|
11
|
+
rake (0.9.2.2)
|
12
|
+
thor (0.14.6)
|
13
|
+
ya2yaml (0.30)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
i18n
|
20
|
+
jeweler
|
21
|
+
nokogiri
|
22
|
+
thor
|
23
|
+
ya2yaml
|
data/README.textile
CHANGED
@@ -17,8 +17,11 @@ h2. Requirements
|
|
17
17
|
h2. Installation
|
18
18
|
|
19
19
|
<pre>
|
20
|
-
gem install
|
21
|
-
|
20
|
+
gem install bundler
|
21
|
+
bundle install
|
22
|
+
|
23
|
+
|
24
|
+
thor cldr:download
|
22
25
|
</pre>
|
23
26
|
|
24
27
|
h2. Export
|
@@ -57,12 +60,12 @@ E.g.:
|
|
57
60
|
format.apply(1234.567)
|
58
61
|
# => "1 234,57"
|
59
62
|
|
60
|
-
calendar = Cldr::Data::Calendars.new(:de)[:calendars][:gregorian]
|
61
|
-
format = Cldr::Format::Date.new('EEEE, d. MMMM y', calendar)
|
63
|
+
calendar = Cldr::Export::Data::Calendars.new(:de)[:calendars][:gregorian]
|
64
|
+
format = Cldr::Export::Format::Date.new('EEEE, d. MMMM y', calendar)
|
62
65
|
format.apply(Date.new(2010, 1, 11))
|
63
66
|
# => "Montag, 11. Januar 2010"
|
64
67
|
|
65
|
-
calendar = Cldr::Data::Calendars.new(:de)[:calendars][:gregorian]
|
68
|
+
calendar = Cldr::Export::Data::Calendars.new(:de)[:calendars][:gregorian]
|
66
69
|
format = Cldr::Format::Time.new('HH:mm:ss z', calendar)
|
67
70
|
format.apply(Time.utc(2010, 1, 1, 13, 12, 11))
|
68
71
|
# => "13:12:11 UTC"
|
@@ -100,5 +103,5 @@ h2. Resources
|
|
100
103
|
For additional information on CLDR plural rules see:
|
101
104
|
|
102
105
|
* "http://unicode.org/draft/reports/tr35/tr35.html#Language_Plural_Rules":http://unicode.org/draft/reports/tr35/tr35.html#Language_Plural_Rules
|
103
|
-
* "http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html":http://www.unicode.org/cldr/data/charts/supplemental/language_plural_rules.html
|
106
|
+
* "http://www.unicode.org/cldr/export/data/charts/supplemental/language_plural_rules.html":http://www.unicode.org/cldr/export/data/charts/supplemental/language_plural_rules.html
|
104
107
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/cldr.rb
CHANGED
data/lib/cldr/data.rb
CHANGED
@@ -1,34 +1,14 @@
|
|
1
1
|
require 'core_ext/string/camelize'
|
2
2
|
|
3
|
-
|
3
|
+
module Cldr
|
4
4
|
module Data
|
5
|
-
autoload :
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
autoload :Timezones, 'cldr/data/timezones'
|
14
|
-
autoload :Units, 'cldr/data/units'
|
15
|
-
|
16
|
-
class << self
|
17
|
-
def dir
|
18
|
-
@dir ||= File.expand_path('./vendor/cldr/common')
|
19
|
-
end
|
20
|
-
|
21
|
-
def dir=(dir)
|
22
|
-
@dir = dir
|
23
|
-
end
|
24
|
-
|
25
|
-
def locales
|
26
|
-
Dir["#{dir}/main/*.xml"].map { |path| path =~ /([\w_-]+)\.xml/ && $1 }
|
27
|
-
end
|
28
|
-
|
29
|
-
def components
|
30
|
-
self.constants.sort - [:Base, :Export]
|
31
|
-
end
|
32
|
-
end
|
5
|
+
# autoload :De, 'data/de'
|
6
|
+
#
|
7
|
+
# class << self
|
8
|
+
# def [](locale)
|
9
|
+
# @data ||= {}
|
10
|
+
# @data[locale] ||= const_get(locale.to_s.camelize)
|
11
|
+
# end
|
12
|
+
# end
|
33
13
|
end
|
34
14
|
end
|
data/lib/cldr/download.rb
CHANGED
@@ -3,10 +3,10 @@ require 'net/http'
|
|
3
3
|
require 'uri'
|
4
4
|
require 'tempfile'
|
5
5
|
|
6
|
-
|
6
|
+
module Cldr
|
7
7
|
class << self
|
8
8
|
def download(source = nil, target = nil)
|
9
|
-
source ||= 'http://unicode.org/Public/cldr/
|
9
|
+
source ||= 'http://unicode.org/Public/cldr/21/core.zip'
|
10
10
|
target ||= File.expand_path('./vendor/cldr')
|
11
11
|
|
12
12
|
source = URI.parse(source)
|
data/lib/cldr/export.rb
CHANGED
@@ -4,8 +4,10 @@ require 'core_ext/string/camelize'
|
|
4
4
|
require 'core_ext/string/underscore'
|
5
5
|
require 'core_ext/hash/deep_stringify_keys'
|
6
6
|
|
7
|
-
|
7
|
+
module Cldr
|
8
8
|
module Export
|
9
|
+
autoload :Code, 'cldr/export/code'
|
10
|
+
autoload :Data, 'cldr/export/data'
|
9
11
|
autoload :Ruby, 'cldr/export/ruby'
|
10
12
|
autoload :Yaml, 'cldr/export/yaml'
|
11
13
|
|
@@ -41,7 +43,11 @@ class Cldr
|
|
41
43
|
else
|
42
44
|
data = locales(locale, options).inject({}) do |result, locale|
|
43
45
|
data = Data.const_get(component.to_s.camelize).new(locale)
|
44
|
-
|
46
|
+
if data
|
47
|
+
data.is_a?(Hash) ? data.deep_merge(result) : data
|
48
|
+
else
|
49
|
+
result
|
50
|
+
end
|
45
51
|
end
|
46
52
|
# data = resolve_links if options[:merge] TODO!!
|
47
53
|
data
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Cldr
|
2
|
+
module Export
|
3
|
+
module Code
|
4
|
+
# autoload :Base, 'cldr/export/code/base'
|
5
|
+
# autoload :Calendars, 'cldr/export/code/calendars'
|
6
|
+
# autoload :Currencies, 'cldr/export/code/currencies'
|
7
|
+
# autoload :Delimiters, 'cldr/export/code/delimiters'
|
8
|
+
# autoload :Languages, 'cldr/export/code/languages'
|
9
|
+
autoload :Numbers, 'cldr/export/code/numbers'
|
10
|
+
# autoload :Plurals, 'cldr/export/code/plurals'
|
11
|
+
# autoload :Territories, 'cldr/export/code/territories'
|
12
|
+
# autoload :Timezones, 'cldr/export/code/timezones'
|
13
|
+
# autoload :Units, 'cldr/export/code/units'
|
14
|
+
#
|
15
|
+
# class << self
|
16
|
+
# def dir
|
17
|
+
# @dir ||= File.expand_path('./vendor/cldr/common')
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# def dir=(dir)
|
21
|
+
# @dir = dir
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# def locales
|
25
|
+
# Dir["#{dir}/main/*.xml"].map { |path| path =~ /([\w_-]+)\.xml/ && $1 }
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# def components
|
29
|
+
# self.constants.sort - [:Base, :Export]
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# module Cldr
|
2
|
+
# module Export
|
3
|
+
# module Code
|
4
|
+
# end
|
5
|
+
# end
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# export code like this:
|
9
|
+
#
|
10
|
+
# module Cldr::Data::De
|
11
|
+
# module Numbers
|
12
|
+
# def self.symbols
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# module Format
|
16
|
+
# def self.currency
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# def self.decimal
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# def self.percent
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# def self.scientific
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
# end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'core_ext/string/camelize'
|
2
|
+
|
3
|
+
module Cldr
|
4
|
+
module Export
|
5
|
+
module Data
|
6
|
+
autoload :Base, 'cldr/export/data/base'
|
7
|
+
autoload :Calendars, 'cldr/export/data/calendars'
|
8
|
+
autoload :Currencies, 'cldr/export/data/currencies'
|
9
|
+
autoload :Delimiters, 'cldr/export/data/delimiters'
|
10
|
+
autoload :Languages, 'cldr/export/data/languages'
|
11
|
+
autoload :Numbers, 'cldr/export/data/numbers'
|
12
|
+
autoload :Plurals, 'cldr/export/data/plurals'
|
13
|
+
autoload :Territories, 'cldr/export/data/territories'
|
14
|
+
autoload :Timezones, 'cldr/export/data/timezones'
|
15
|
+
autoload :Units, 'cldr/export/data/units'
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def dir
|
19
|
+
@dir ||= File.expand_path('./vendor/cldr/common')
|
20
|
+
end
|
21
|
+
|
22
|
+
def dir=(dir)
|
23
|
+
@dir = dir
|
24
|
+
end
|
25
|
+
|
26
|
+
def locales
|
27
|
+
Dir["#{dir}/main/*.xml"].map { |path| path =~ /([\w_-]+)\.xml/ && $1 }
|
28
|
+
end
|
29
|
+
|
30
|
+
def components
|
31
|
+
self.constants.sort - [:Base, :Export]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'core_ext/string/underscore'
|
2
|
+
require 'core_ext/hash/deep_merge'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module Cldr
|
6
|
+
module Export
|
7
|
+
module Data
|
8
|
+
class Base < Hash
|
9
|
+
attr_reader :locale
|
10
|
+
|
11
|
+
def initialize(locale)
|
12
|
+
@locale = locale
|
13
|
+
end
|
14
|
+
|
15
|
+
def update(hash)
|
16
|
+
hash.each { |key, value| self[key] = value }
|
17
|
+
end
|
18
|
+
|
19
|
+
def []=(key, value)
|
20
|
+
store(key, value) unless value.nil? || value.respond_to?(:empty?) && value.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def plural?(node)
|
26
|
+
!!node.attribute('count')
|
27
|
+
end
|
28
|
+
|
29
|
+
def draft?(node)
|
30
|
+
draft = node.attribute('draft')
|
31
|
+
draft && draft.value == 'unconfirmed'
|
32
|
+
end
|
33
|
+
|
34
|
+
def name(node)
|
35
|
+
node.name.underscore
|
36
|
+
end
|
37
|
+
|
38
|
+
def count(node)
|
39
|
+
node.attribute('count').value
|
40
|
+
end
|
41
|
+
|
42
|
+
def select(*sources)
|
43
|
+
doc.xpath(xpath(sources))
|
44
|
+
end
|
45
|
+
|
46
|
+
def xpath(sources)
|
47
|
+
path = sources.map { |source| source.respond_to?(:path) ? source.path : source }.join('/')
|
48
|
+
path =~ /^\/?\/ldml/ ? path : "//ldml/#{path}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def doc
|
52
|
+
@doc ||= Nokogiri::XML(File.read(path))
|
53
|
+
end
|
54
|
+
|
55
|
+
def path
|
56
|
+
@path ||= "#{Cldr::Export::Data.dir}/main/#{locale.to_s.gsub('-', '_')}.xml"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Cldr
|
2
|
+
module Export
|
3
|
+
module Data
|
4
|
+
class Calendars < Base
|
5
|
+
autoload :Gregorian, 'cldr/export/data/calendars/gregorian'
|
6
|
+
|
7
|
+
def initialize(locale)
|
8
|
+
super
|
9
|
+
update(:calendars => { :gregorian => Gregorian.new(locale) })
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module Cldr
|
2
|
+
module Export
|
3
|
+
module Data
|
4
|
+
class Calendars
|
5
|
+
class Gregorian < Base
|
6
|
+
def initialize(locale)
|
7
|
+
super
|
8
|
+
update(
|
9
|
+
:months => contexts('month'),
|
10
|
+
:days => contexts('day'),
|
11
|
+
:eras => eras,
|
12
|
+
:quarters => contexts('quarter'),
|
13
|
+
:periods => contexts('dayPeriod'),
|
14
|
+
:fields => fields,
|
15
|
+
:formats => {
|
16
|
+
:date => formats('date'),
|
17
|
+
:time => formats('time'),
|
18
|
+
:datetime => formats('dateTime')
|
19
|
+
}
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def calendar
|
24
|
+
@calendar ||= select('dates/calendars/calendar[@type="gregorian"]').first
|
25
|
+
end
|
26
|
+
|
27
|
+
def contexts(kind)
|
28
|
+
select(calendar, "#{kind}s/#{kind}Context").inject({}) do |result, node|
|
29
|
+
context = node.attribute('type').value.to_sym
|
30
|
+
result[context] = widths(node, kind, context)
|
31
|
+
result
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def widths(node, kind, context)
|
36
|
+
select(node, "#{kind}Width").inject({}) do |result, node|
|
37
|
+
width = node.attribute('type').value.to_sym
|
38
|
+
result[width] = elements(node, kind, context, width)
|
39
|
+
result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def elements(node, kind, context, width)
|
44
|
+
aliased = select(node, 'alias').first
|
45
|
+
if aliased
|
46
|
+
xpath_to_key(aliased.attribute('path').value, kind, context, width)
|
47
|
+
else
|
48
|
+
select(node, kind).inject({}) do |result, node|
|
49
|
+
key = node.attribute('type').value
|
50
|
+
key = key =~ /^\d*$/ ? key.to_i : key.to_sym
|
51
|
+
result[key] = node.content
|
52
|
+
result
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def xpath_to_key(xpath, kind, context, width)
|
58
|
+
kind = (xpath =~ %r(/([^\/]*)Width) && $1) || kind
|
59
|
+
context = (xpath =~ %r(Context\[@type='([^\/]*)'\]) && $1) || context
|
60
|
+
width = (xpath =~ %r(Width\[@type='([^\/]*)'\]) && $1) || width
|
61
|
+
:"calendars.gregorian.#{kind}s.#{context}.#{width}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def xpath_width
|
65
|
+
end
|
66
|
+
|
67
|
+
def periods
|
68
|
+
am = select(calendar, "am").first
|
69
|
+
pm = select(calendar, "pm").first
|
70
|
+
|
71
|
+
result = {}
|
72
|
+
result[:am] = am.content if am
|
73
|
+
result[:pm] = pm.content if pm
|
74
|
+
result
|
75
|
+
end
|
76
|
+
|
77
|
+
def eras
|
78
|
+
base_path = calendar.path.gsub('/ldml/', '') + '/eras'
|
79
|
+
keys = select("#{base_path}/*").map { |node| node.name }
|
80
|
+
|
81
|
+
keys.inject({}) do |result, name|
|
82
|
+
path = "#{base_path}/#{name}/*"
|
83
|
+
key = name.gsub('era', '').gsub(/s$/, '').downcase.to_sym
|
84
|
+
result[key] = select(path).inject({}) do |ret, node|
|
85
|
+
type = node.attribute('type').value.to_i rescue 0
|
86
|
+
ret[type] = node.content
|
87
|
+
ret
|
88
|
+
end
|
89
|
+
result
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def extract(path, lambdas)
|
94
|
+
nodes = select(path)
|
95
|
+
nodes.inject({}) do |ret, node|
|
96
|
+
key = lambdas[:key].call(node)
|
97
|
+
ret[key] = lambdas[:value].call(node)
|
98
|
+
ret
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def formats(type)
|
103
|
+
formats = select(calendar, "#{type}Formats/#{type}FormatLength").inject({}) do |result, node|
|
104
|
+
key = node.attribute('type').value.to_sym rescue :format
|
105
|
+
result[key] = pattern(node, type)
|
106
|
+
result
|
107
|
+
end
|
108
|
+
if default = default_format(type)
|
109
|
+
formats = default.merge(formats)
|
110
|
+
end
|
111
|
+
formats
|
112
|
+
end
|
113
|
+
|
114
|
+
def default_format(type)
|
115
|
+
if node = select(calendar, "#{type}Formats/default").first
|
116
|
+
key = node.attribute('choice').value.to_sym
|
117
|
+
{ :default => :"calendars.gregorian.formats.#{type.downcase}.#{key}" }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def pattern(node, type)
|
122
|
+
select(node, "#{type}Format/pattern").inject({}) do |result, node|
|
123
|
+
pattern = node.content
|
124
|
+
pattern = pattern.gsub('{0}', '{{time}}').gsub('{1}', '{{date}}') if type == 'dateTime'
|
125
|
+
result[:pattern] = pattern
|
126
|
+
result
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def fields
|
131
|
+
select(calendar, "fields/field").inject({}) do |result, node|
|
132
|
+
key = node.attribute('type').value.to_sym
|
133
|
+
name = node.xpath('displayName').first
|
134
|
+
result[key] = name.content if name
|
135
|
+
result
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|