when_exe 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE.ja.txt +8 -21
- data/LICENSE.txt +5 -27
- data/README.md +25 -79
- data/bin/.pryrc +9 -0
- data/bin/make_ttl.rb +3 -2
- data/bin/make_ttl.rb.config +3 -3
- data/lib/when_exe.rb +101 -5
- data/lib/when_exe/basictypes.rb +47 -16
- data/lib/when_exe/calendarnote.rb +27 -18
- data/lib/when_exe/calendartypes.rb +12 -50
- data/lib/when_exe/coordinates.rb +37 -391
- data/lib/when_exe/ephemeris.rb +53 -14
- data/lib/when_exe/ephemeris/eclipse.rb +8 -8
- data/lib/when_exe/ephemeris/moon.rb +333 -333
- data/lib/when_exe/ephemeris/notes.rb +29 -17
- data/lib/when_exe/ephemeris/phase_table.rb +825 -0
- data/lib/when_exe/ephemeris/term_table.rb +603 -0
- data/lib/when_exe/events.rb +1888 -0
- data/lib/when_exe/google_api.rb +26 -31
- data/lib/when_exe/icalendar.rb +129 -12
- data/lib/when_exe/inspect.rb +5 -5
- data/lib/when_exe/linkeddata.rb +43 -23
- data/lib/when_exe/locales/akt.rb +63 -0
- data/lib/when_exe/locales/encoding_conversion.rb +134 -134
- data/lib/when_exe/locales/iast.rb +90 -90
- data/lib/when_exe/locales/locale.rb +88 -18
- data/lib/when_exe/locales/transliteration_table.rb +62 -62
- data/lib/when_exe/mini_application.rb +14 -8
- data/lib/when_exe/namespace.rb +42 -0
- data/lib/when_exe/parts/enumerator.rb +16 -5
- data/lib/when_exe/parts/geometric_complex.rb +52 -2
- data/lib/when_exe/parts/method_cash.rb +229 -224
- data/lib/when_exe/parts/resource.rb +65 -35
- data/lib/when_exe/parts/timezone.rb +25 -34
- data/lib/when_exe/region/balinese.rb +5 -3
- data/lib/when_exe/region/chinese.rb +39 -11
- data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
- data/lib/when_exe/region/chinese/epochs.rb +7 -7
- data/lib/when_exe/region/chinese/notes.rb +3 -3
- data/lib/when_exe/region/chinese/twins.rb +134 -11
- data/lib/when_exe/region/dee.rb +4 -4
- data/lib/when_exe/region/discordian.rb +1 -1
- data/lib/when_exe/region/geologicalage.rb +139 -128
- data/lib/when_exe/region/hanke_henry.rb +4 -4
- data/lib/when_exe/region/indian.rb +77 -8
- data/lib/when_exe/region/international_fixed.rb +3 -3
- data/lib/when_exe/region/islamic.rb +1 -1
- data/lib/when_exe/region/japanese.rb +12 -8
- data/lib/when_exe/region/japanese/calendars.rb +397 -397
- data/lib/when_exe/region/japanese/eclipses.rb +1194 -1194
- data/lib/when_exe/region/japanese/epochs.rb +8 -4
- data/lib/when_exe/region/japanese/location.rb +93 -0
- data/lib/when_exe/region/japanese/nihon_shoki.rb +70 -70
- data/lib/when_exe/region/japanese/notes.rb +57 -18
- data/lib/when_exe/region/japanese/residues.rb +33 -11
- data/lib/when_exe/region/japanese/twins.rb +27 -14
- data/lib/when_exe/region/japanese/weeks.rb +7 -7
- data/lib/when_exe/region/korean.rb +384 -384
- data/lib/when_exe/region/location.rb +40 -0
- data/lib/when_exe/region/martian.rb +1 -1
- data/lib/when_exe/region/mayan.rb +2 -2
- data/lib/when_exe/region/roman.rb +2 -2
- data/lib/when_exe/region/ryukyu.rb +101 -101
- data/lib/when_exe/region/saudi_arabian.rb +57 -0
- data/lib/when_exe/region/shire.rb +1 -1
- data/lib/when_exe/region/world.rb +3 -3
- data/lib/when_exe/region/zoroastrian.rb +1 -1
- data/lib/when_exe/spatial.rb +611 -0
- data/lib/when_exe/timestandard.rb +9 -7
- data/lib/when_exe/tmobjects.rb +34 -2
- data/lib/when_exe/tmposition.rb +225 -1322
- data/lib/when_exe/tmptypes.rb +1279 -0
- data/lib/when_exe/tmreference.rb +42 -7
- data/lib/when_exe/version.rb +3 -3
- data/test/events/example-datasets +6 -0
- data/test/events/history-dataset.csv +22 -0
- data/test/events/japanese-holiday-index.csv +28 -0
- data/test/events/japanese-holiday.csv +94 -0
- data/test/events/japanese-holiday.ttl +948 -0
- data/test/events/make_events_ttl.rb +18 -0
- data/test/events/mori_wikichoshi.csv +14 -0
- data/test/events/ndl_koyomi.csv +220 -0
- data/test/events/ndl_koyomi_index.csv +44 -0
- data/test/events/primeminister-dataset.csv +19 -0
- data/test/events/shogun-dataset.csv +22 -0
- data/test/events/test-history-dataset-edge-sparql.csv +26 -0
- data/test/events/test-history-dataset-edge.csv +27 -0
- data/test/events/test-history-dataset-sparql.csv +22 -0
- data/test/events/test-history-dataset.csv +23 -0
- data/test/events/test-history-events-edge.ttl +89 -0
- data/test/events/test-history-events.csv +6 -0
- data/test/examples/JapanHolidays.ics +2 -2
- data/test/examples/JapanHolidaysRFC6350.ics +3 -3
- data/test/examples/Residue.m17n +2 -2
- data/test/examples/Spatial.m17n +3 -3
- data/test/examples/Terms.m17n +3 -3
- data/test/scripts/8.ext.rb +6 -6
- data/test/scripts/8.rb +6 -6
- data/test/scripts/geometric_complex.rb +41 -41
- data/test/scripts/korea.rb +59 -59
- data/test/scripts/thai.rb +36 -36
- data/test/test.rb +6 -0
- data/test/test/basictypes.rb +431 -431
- data/test/test/calendarnote.rb +86 -86
- data/test/test/calendartypes.rb +97 -97
- data/test/test/coordinates.rb +399 -397
- data/test/test/ephemeris.rb +115 -115
- data/test/test/ephemeris/moon.rb +14 -14
- data/test/test/ephemeris/planets.rb +14 -14
- data/test/test/ephemeris/sun.rb +14 -14
- data/test/test/events.rb +32 -0
- data/test/test/google_api.rb +45 -32
- data/test/test/inspect.rb +153 -153
- data/test/test/parts.rb +488 -488
- data/test/test/region/armenian.rb +20 -20
- data/test/test/region/bahai.rb +58 -58
- data/test/test/region/balinese.rb +34 -34
- data/test/test/region/chinese.rb +229 -229
- data/test/test/region/christian.rb +226 -226
- data/test/test/region/coptic.rb +27 -27
- data/test/test/region/discordian.rb +20 -20
- data/test/test/region/french.rb +33 -33
- data/test/test/region/geologicalage.rb +17 -17
- data/test/test/region/indian.rb +14 -1
- data/test/test/region/iran.rb +54 -54
- data/test/test/region/islamic.rb +64 -54
- data/test/test/region/japanese.rb +281 -261
- data/test/test/region/jewish.rb +63 -63
- data/test/test/region/m17n.rb +21 -21
- data/test/test/region/mayan.rb +17 -16
- data/test/test/region/reforms.rb +2 -2
- data/test/test/region/residue.rb +7 -7
- data/test/test/region/shire.rb +58 -58
- data/test/test/region/swedish.rb +45 -45
- data/test/test/region/thai.rb +116 -116
- data/test/test/region/tibetan.rb +30 -30
- data/test/test/region/vietnamese.rb +102 -102
- data/test/test/region/zoroastrian.rb +58 -58
- data/test/test/timestandard.rb +81 -81
- data/test/test/tmobjects.rb +402 -402
- data/test/test/tmposition.rb +66 -4
- data/test/test/tmreference.rb +157 -157
- metadata +36 -93
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2011-
|
3
|
+
Copyright (C) 2011-2021 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -28,7 +28,7 @@ module When
|
|
28
28
|
|
29
29
|
# 省略時 Namespace
|
30
30
|
DefaultNamespaces = Hash.new {|hash, key|
|
31
|
-
hash[key] = "
|
31
|
+
hash[key] = "https://#{key}.wikipedia.org/wiki/"
|
32
32
|
}.update({
|
33
33
|
'mailto' => false,
|
34
34
|
'https' => false,
|
@@ -57,12 +57,16 @@ module When
|
|
57
57
|
|
58
58
|
# Wikipedia の URL の正規表現
|
59
59
|
# @private
|
60
|
-
Ref = /\
|
60
|
+
Ref = /\Ahttps?:\/\/(.+?)\.wikipedia\.org\/wiki\/([^#]+?)\z/
|
61
61
|
|
62
62
|
# Wikipedia の多言語リンクの正規表現
|
63
63
|
# @private
|
64
64
|
Link = /<li class="interlanguage-link interwiki-(.+?)"><a href="\/\/(.+?)\.wikipedia\.org\/wiki\/(.+?)" title="(.+?) – /
|
65
65
|
|
66
|
+
# NUL for Escape
|
67
|
+
# @private
|
68
|
+
NUL = 0.chr
|
69
|
+
|
66
70
|
class << self
|
67
71
|
|
68
72
|
# Wikipedia の連続的な参照を抑制するための遅延時間/秒
|
@@ -75,7 +79,7 @@ module When
|
|
75
79
|
#
|
76
80
|
# @param [Hash] options 下記の通り
|
77
81
|
# @option options [Hash] :alias Locale の読み替えパターンを Hash で指定する。
|
78
|
-
# @option options [Hash] :
|
82
|
+
# @option options [Hash] :namespace_format 名前空間定義の省略時に名前空間生成に用いる書式
|
79
83
|
# @option options [Hash] :unification 漢字の包摂パターンを Hash で指定する。
|
80
84
|
# @option options [Numeric] :wikipedia_interval Wikipedia の連続的な参照を抑制するための遅延時間/秒
|
81
85
|
#
|
@@ -85,7 +89,7 @@ module When
|
|
85
89
|
#
|
86
90
|
def _setup_(options={})
|
87
91
|
@aliases = options[:alias] || DefaultAlias
|
88
|
-
@namespaces = options[:
|
92
|
+
@namespaces = options[:namespace_format] || DefaultNamespaces
|
89
93
|
@unifications = options[:unification] || DefaultUnification
|
90
94
|
@wikipedia_interval = options[:wikipedia_interval]
|
91
95
|
end
|
@@ -96,7 +100,7 @@ module When
|
|
96
100
|
#
|
97
101
|
def _setup_info
|
98
102
|
{:alias => _alias,
|
99
|
-
:
|
103
|
+
:namespace_format => _namespaces,
|
100
104
|
:unification => _unification,
|
101
105
|
:wikipedia_interval => @wikipedia_interval}
|
102
106
|
end
|
@@ -134,6 +138,29 @@ module When
|
|
134
138
|
source
|
135
139
|
end
|
136
140
|
|
141
|
+
# 暦要素を含む文字列を Hash に分解する
|
142
|
+
#
|
143
|
+
# @param [String] date_time 暦要素を含む文字列
|
144
|
+
# @param [String or Hash] format 分解する書式
|
145
|
+
# @param [String] locale 言語指定
|
146
|
+
#
|
147
|
+
# @return [Hash] 暦要素を分解格納した Hash
|
148
|
+
#
|
149
|
+
def _to_date_time_hash(date_time, format, locale=nil)
|
150
|
+
if locale
|
151
|
+
format = format.kind_of?(String) ?
|
152
|
+
translate(format, locale) :
|
153
|
+
_hash_value(format, locale)
|
154
|
+
unless locale == 'en'
|
155
|
+
regexp, hash = _trans_table(locale)
|
156
|
+
date_time = date_time.gsub(regexp) {|match| hash[match]}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
::DateTime._strptime(date_time, format)
|
160
|
+
rescue NameError
|
161
|
+
raise "Please require standard library 'Date' or 'DateTime'"
|
162
|
+
end
|
163
|
+
|
137
164
|
# 包摂リストに登録されている文字を包摂する
|
138
165
|
#
|
139
166
|
# @param [When::Locale] source 文字を包摂しようとする国際化文字列
|
@@ -243,20 +270,27 @@ module When
|
|
243
270
|
}
|
244
271
|
end
|
245
272
|
|
246
|
-
# locale 指定を解析して
|
273
|
+
# locale 指定を解析して key の値を取り出す
|
247
274
|
# @private
|
248
|
-
def
|
275
|
+
def _hash_key(hash, locale, defaults=['', 'en'])
|
249
276
|
locale = locale.sub(/\..*/, '')
|
250
|
-
return
|
251
|
-
return
|
252
|
-
language = locale.sub(
|
253
|
-
return
|
277
|
+
return locale if hash.key?(locale)
|
278
|
+
return _hash_key(hash, _alias[locale], defaults) if _alias.key?(locale)
|
279
|
+
language = locale.sub(/[-_].*/, '')
|
280
|
+
return language if hash.key?(language)
|
254
281
|
defaults.each do |default|
|
255
|
-
return
|
282
|
+
return default if hash.key?(default)
|
256
283
|
end
|
257
284
|
return nil
|
258
285
|
end
|
259
286
|
|
287
|
+
# locale 指定を解析して Hash の値を取り出す
|
288
|
+
# @private
|
289
|
+
def _hash_value(hash, locale, defaults=['', 'en'])
|
290
|
+
key = _hash_key(hash, locale, defaults)
|
291
|
+
key ? hash[key] : nil
|
292
|
+
end
|
293
|
+
|
260
294
|
# 漢字の包摂パターン
|
261
295
|
# @private
|
262
296
|
def _unification
|
@@ -269,12 +303,23 @@ module When
|
|
269
303
|
access_key = access_key.split(/\//).map {|key| key =~ /\A[0-9]+\z/ ? key.to_i : key}
|
270
304
|
locale = locale.sub(/\..*/, '')
|
271
305
|
[locale, locale.sub(/-.*/, '')].each do |loc|
|
272
|
-
symbol = ('Locale_' + loc.
|
306
|
+
symbol = ('Locale_' + loc.gsub(/-/,'_')).to_sym
|
273
307
|
return {locale=>access_key.inject(const_get(symbol)) {|hash, key| hash = hash[key]}} if const_defined?(symbol)
|
274
308
|
end
|
275
309
|
return nil
|
276
310
|
end
|
277
311
|
|
312
|
+
# DBpedia IRI の取得
|
313
|
+
#
|
314
|
+
# @param [String] source もとの URI
|
315
|
+
#
|
316
|
+
# @return [String] DBpedia IRI
|
317
|
+
# @private
|
318
|
+
def _dbpedia(source)
|
319
|
+
return nil unless Ref =~ source
|
320
|
+
return "http://#{$1=='en' ? '' : $1+'.'}dbpedia.org/resource/#{CGI.unescape($2)}"
|
321
|
+
end
|
322
|
+
|
278
323
|
private
|
279
324
|
|
280
325
|
# Locale の読み替えパターン
|
@@ -298,7 +343,7 @@ module When
|
|
298
343
|
# wikipedia の読み込み
|
299
344
|
def _wikipedia_object(path, locale, file, query, interval, options)
|
300
345
|
# 採取済みデータ
|
301
|
-
title =
|
346
|
+
title = CGI.unescape(file.gsub('_', ' '))
|
302
347
|
mode = "".respond_to?(:force_encoding) ? ':utf-8' : ''
|
303
348
|
dir = When::Parts::Resource.root_dir + '/data/wikipedia/' + locale
|
304
349
|
FileUtils.mkdir_p(dir) unless FileTest.exist?(dir)
|
@@ -325,7 +370,7 @@ module When
|
|
325
370
|
contents = nil
|
326
371
|
begin
|
327
372
|
OpenURI
|
328
|
-
source = open
|
373
|
+
source = URI.send(:open, path, 'r'+mode, {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE})
|
329
374
|
contents = source.read
|
330
375
|
ensure
|
331
376
|
@wikipedia_last_access = Time.now.to_f
|
@@ -343,7 +388,7 @@ module When
|
|
343
388
|
}
|
344
389
|
contents.scan(Link) do |link|
|
345
390
|
word[:names][$2] = $4
|
346
|
-
word[:link ][$2] = "
|
391
|
+
word[:link ][$2] = "https://#{$2}.wikipedia.org/wiki/#{$3}"
|
347
392
|
end
|
348
393
|
object = When::BasicTypes::M17n.new(word)
|
349
394
|
|
@@ -380,6 +425,21 @@ module When
|
|
380
425
|
object._pool['..'] += '?' + query if query
|
381
426
|
object
|
382
427
|
end
|
428
|
+
|
429
|
+
# 月名と週名の翻訳テーブル
|
430
|
+
def _trans_table(locale)
|
431
|
+
return @trans_table[locale] if @trans_table && @trans_table[locale]
|
432
|
+
hash = Hash[*(%w(_m:Calendar::Month::* _m:Calendar::Abbr_Month::*
|
433
|
+
_co:Common::Week::* _co:Common::Abbr_Day::*).inject([]) {|list, iri|
|
434
|
+
list.concat(When.Resource(iri).map {|resource|
|
435
|
+
label = resource.kind_of?(When::BasicTypes::M17n) ? resource : resource.label
|
436
|
+
[label.translate(locale), label.translate('en')]
|
437
|
+
})
|
438
|
+
}.sort_by {|pair| -(pair.first.length*100+pair.last.length)}).flatten]
|
439
|
+
regexp = /#{hash.keys.sort_by {|key| -key.length}.join('|')}/
|
440
|
+
@trans_table ||= {}
|
441
|
+
@trans_table[locale] = [regexp, hash]
|
442
|
+
end
|
383
443
|
end
|
384
444
|
|
385
445
|
# ローケール指定時の文字列
|
@@ -438,6 +498,16 @@ module When
|
|
438
498
|
return Locale._hash_value(@link, loc.sub('_', '-'))
|
439
499
|
end
|
440
500
|
|
501
|
+
# 特定 locale に対応した DBpedia URI の取得
|
502
|
+
#
|
503
|
+
# @param [String] loc locale の指定
|
504
|
+
#
|
505
|
+
# @return [String] loc に対応した DBpedia URI
|
506
|
+
#
|
507
|
+
def dbpedia(loc='')
|
508
|
+
Locale._dbpedia(reference(loc))
|
509
|
+
end
|
510
|
+
|
441
511
|
# 部分文字列
|
442
512
|
#
|
443
513
|
# @param [Range] range String#[] と同様の指定方法で範囲を指定する
|
@@ -764,7 +834,7 @@ module When
|
|
764
834
|
# encode URI from patterns %%(...) or %.(...) and replace space to '_'
|
765
835
|
def _encode(source)
|
766
836
|
source.gsub(' ','_').gsub(/%.<.+?>/) { |match|
|
767
|
-
|
837
|
+
CGI.escape(match[3..-2]).gsub('%', match[1..1])
|
768
838
|
}
|
769
839
|
end
|
770
840
|
end
|
@@ -1,62 +1,62 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
=begin
|
3
|
-
Copyright (C) 2014 Takashi SUGA
|
4
|
-
|
5
|
-
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
|
-
=end
|
7
|
-
|
8
|
-
module When
|
9
|
-
module Locale
|
10
|
-
class << self
|
11
|
-
|
12
|
-
#
|
13
|
-
# Generate Regexp for transliteration
|
14
|
-
#
|
15
|
-
# @param [Hash] hash transliteration table
|
16
|
-
#
|
17
|
-
# @return [Regexp] Regexp for transliteration
|
18
|
-
#
|
19
|
-
def transliteration_keys(hash)
|
20
|
-
Regexp.new((hash.keys.sort_by {|key| -key.length} + ['%.*?[A-Za-z]']).join('|'))
|
21
|
-
end
|
22
|
-
|
23
|
-
#
|
24
|
-
# Generate Hash of {locale=>Regexp} for transliteration
|
25
|
-
#
|
26
|
-
# @param [Hash] hash transliteration table hash
|
27
|
-
#
|
28
|
-
# @return [Hash{String=>Regexp}] Hash of {locale=>Regexp} for transliteration
|
29
|
-
#
|
30
|
-
def transliteration_keys_hash(hash)
|
31
|
-
Hash[*(hash.keys.map {|locale|
|
32
|
-
[locale, transliteration_keys(hash[locale])]
|
33
|
-
}).flatten]
|
34
|
-
end
|
35
|
-
|
36
|
-
alias :_method_missing :method_missing
|
37
|
-
|
38
|
-
#
|
39
|
-
# Registlation of conversion method
|
40
|
-
#
|
41
|
-
def method_missing(name, *args, &block)
|
42
|
-
table_name = name.to_s.upcase
|
43
|
-
return _method_missing(name, *args, &block) unless table_name !~ /_/ && const_defined?(table_name)
|
44
|
-
table_obj = const_get(table_name)
|
45
|
-
default = table_obj.keys.first
|
46
|
-
locale = args[1] || default
|
47
|
-
const_set(table_name + '_keys', transliteration_keys_hash(table_obj)) unless const_defined?(table_name + '_keys')
|
48
|
-
return send(name, args[0], locale) if respond_to?(name)
|
49
|
-
instance_eval %Q{
|
50
|
-
def #{name}(string, locale='#{default}')
|
51
|
-
string.gsub(#{table_name}_keys[locale]) do |code|
|
52
|
-
#{table_name}[locale][code] || code
|
53
|
-
end
|
54
|
-
end
|
55
|
-
}
|
56
|
-
args[0].gsub(const_get("#{table_name}_keys")[locale]) do |code|
|
57
|
-
table_obj[locale][code] || code
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2014 Takashi SUGA
|
4
|
+
|
5
|
+
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
|
+
=end
|
7
|
+
|
8
|
+
module When
|
9
|
+
module Locale
|
10
|
+
class << self
|
11
|
+
|
12
|
+
#
|
13
|
+
# Generate Regexp for transliteration
|
14
|
+
#
|
15
|
+
# @param [Hash] hash transliteration table
|
16
|
+
#
|
17
|
+
# @return [Regexp] Regexp for transliteration
|
18
|
+
#
|
19
|
+
def transliteration_keys(hash)
|
20
|
+
Regexp.new((hash.keys.sort_by {|key| -key.length} + ['%.*?[A-Za-z]']).join('|'))
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Generate Hash of {locale=>Regexp} for transliteration
|
25
|
+
#
|
26
|
+
# @param [Hash] hash transliteration table hash
|
27
|
+
#
|
28
|
+
# @return [Hash{String=>Regexp}] Hash of {locale=>Regexp} for transliteration
|
29
|
+
#
|
30
|
+
def transliteration_keys_hash(hash)
|
31
|
+
Hash[*(hash.keys.map {|locale|
|
32
|
+
[locale, transliteration_keys(hash[locale])]
|
33
|
+
}).flatten]
|
34
|
+
end
|
35
|
+
|
36
|
+
alias :_method_missing :method_missing
|
37
|
+
|
38
|
+
#
|
39
|
+
# Registlation of conversion method
|
40
|
+
#
|
41
|
+
def method_missing(name, *args, &block)
|
42
|
+
table_name = name.to_s.upcase
|
43
|
+
return _method_missing(name, *args, &block) unless table_name !~ /_/ && const_defined?(table_name)
|
44
|
+
table_obj = const_get(table_name)
|
45
|
+
default = table_obj.keys.first
|
46
|
+
locale = args[1] || default
|
47
|
+
const_set(table_name + '_keys', transliteration_keys_hash(table_obj)) unless const_defined?(table_name + '_keys')
|
48
|
+
return send(name, args[0], locale) if respond_to?(name)
|
49
|
+
instance_eval %Q{
|
50
|
+
def #{name}(string, locale='#{default}')
|
51
|
+
string.gsub(#{table_name}_keys[locale]) do |code|
|
52
|
+
#{table_name}[locale][code] || code
|
53
|
+
end
|
54
|
+
end
|
55
|
+
}
|
56
|
+
args[0].gsub(const_get("#{table_name}_keys")[locale]) do |code|
|
57
|
+
table_obj[locale][code] || code
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -232,9 +232,6 @@ module When
|
|
232
232
|
calendars[0] ||= When::Gregorian
|
233
233
|
result = dates.map {|date|
|
234
234
|
date = When.when?(date)
|
235
|
-
opts = {}
|
236
|
-
opts[:location] = date.location if date.location
|
237
|
-
opts[:clock ] = date.clock if date.respond_to?(:clock) && date.clock
|
238
235
|
list = calendars.dup
|
239
236
|
(0...calendars.size).to_a.reverse.each do |i|
|
240
237
|
case list[i]
|
@@ -257,15 +254,13 @@ module When
|
|
257
254
|
|
258
255
|
if methods.size == 0
|
259
256
|
list.map {|calendar|
|
260
|
-
|
261
|
-
yield(calendar.new(date, opts.dup)) :
|
262
|
-
yield(calendar.^(calendar.rate_of_clock == date.time_standard.rate_of_clock ? date.to_i : date, opts))
|
257
|
+
yield(date_for_calendar(calendar, date, options))
|
263
258
|
}
|
264
259
|
else
|
265
260
|
list.map {|calendar|
|
266
|
-
|
261
|
+
date_for_cal = date_for_calendar(calendar, date, options)
|
267
262
|
methods.map {|method|
|
268
|
-
|
263
|
+
date_for_cal.send(method[0].to_sym, method[1], &block)
|
269
264
|
}
|
270
265
|
}
|
271
266
|
end
|
@@ -274,6 +269,17 @@ module When
|
|
274
269
|
return result
|
275
270
|
end
|
276
271
|
|
272
|
+
# 当該 Calendar or CalendarEra の TemporalPosition を生成
|
273
|
+
def date_for_calendar(calendar, date, options)
|
274
|
+
opts = {}
|
275
|
+
opts[:location] = date.location if date.location
|
276
|
+
opts[:clock ] = calendar.rate_of_clock == 1.0 ? options[:clock] :
|
277
|
+
calendar.time_basis if date.respond_to?(:clock)
|
278
|
+
calendar.kind_of?(Class) ?
|
279
|
+
calendar.new(date, opts) :
|
280
|
+
calendar.^([calendar.rate_of_clock,date.time_standard.rate_of_clock].uniq == [1.0] ? date.to_i : date, opts)
|
281
|
+
end
|
282
|
+
|
277
283
|
# JSONで通信するために Symbol を String に変換する
|
278
284
|
def _to_string(source)
|
279
285
|
case source
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2015 Takashi SUGA
|
4
|
+
|
5
|
+
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
|
+
=end
|
7
|
+
|
8
|
+
module When
|
9
|
+
module Namespace
|
10
|
+
|
11
|
+
# XML Schema Definition
|
12
|
+
XSD = 'http://www.w3.org/2001/XMLSchema'
|
13
|
+
|
14
|
+
# Resource Description Framework
|
15
|
+
RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
|
16
|
+
|
17
|
+
# Resource Description Framework Schema
|
18
|
+
RDFS = 'http://www.w3.org/2000/01/rdf-schema#'
|
19
|
+
|
20
|
+
# RDF 1.1 Concepts and Abstract Syntax
|
21
|
+
RDFC = 'http://www.w3.org/TR/rdf11-concepts/#'
|
22
|
+
|
23
|
+
# Web Ontology Language
|
24
|
+
OWL = 'http://www.w3.org/2002/07/owl#'
|
25
|
+
|
26
|
+
# Dublin Core
|
27
|
+
DC = 'http://purl.org/dc/elements/1.1/'
|
28
|
+
|
29
|
+
# Dublin Core Terms
|
30
|
+
DCQ = 'http://purl.org/dc/terms/'
|
31
|
+
|
32
|
+
# Dublin Core Types
|
33
|
+
DCT = 'http://purl.org/dc/dcmitype/'
|
34
|
+
|
35
|
+
# Friend of a Friend
|
36
|
+
FOAF = 'http://xmlns.com/foaf/0.1/'
|
37
|
+
|
38
|
+
# RDF Site Summary
|
39
|
+
RSS = 'http://purl.org/rss/1.0/'
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2011-
|
3
|
+
Copyright (C) 2011-2021 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -188,7 +188,7 @@ module When::Parts
|
|
188
188
|
# [ false - ない ]
|
189
189
|
#
|
190
190
|
def has_next?
|
191
|
-
return (@count_limit != 0) &&
|
191
|
+
return (@count_limit != 0) && !@current.nil?
|
192
192
|
end
|
193
193
|
|
194
194
|
#
|
@@ -238,7 +238,17 @@ module When::Parts
|
|
238
238
|
@count += 1
|
239
239
|
_exclude(@current) if @current
|
240
240
|
end
|
241
|
-
|
241
|
+
@delayed && value.respond_to?(:apply_delayed_options) ?
|
242
|
+
value.apply_delayed_options(@delayed) :
|
243
|
+
value
|
244
|
+
end
|
245
|
+
|
246
|
+
# 終端要素は含む
|
247
|
+
#
|
248
|
+
# @return [Boolean]
|
249
|
+
#
|
250
|
+
def exclude_end
|
251
|
+
false
|
242
252
|
end
|
243
253
|
|
244
254
|
# オブジェクトの生成
|
@@ -262,6 +272,7 @@ module When::Parts
|
|
262
272
|
@options = self.class._options(args)
|
263
273
|
@exdate = @options.delete(:exdate)
|
264
274
|
@exevent = @options.delete(:exevent)
|
275
|
+
@delayed = @options.delete(:delayed)
|
265
276
|
@parent, *rest = args
|
266
277
|
_range(rest)
|
267
278
|
_rewind
|
@@ -302,7 +313,7 @@ module When::Parts
|
|
302
313
|
end
|
303
314
|
end
|
304
315
|
previous = @processed._include?(value)
|
305
|
-
@processed |= value
|
316
|
+
@processed |= value unless previous
|
306
317
|
registered = (previous==value) ? previous : value
|
307
318
|
registered = registered.first if registered.kind_of?(GeometricComplex)
|
308
319
|
registered.events ||=[]
|
@@ -341,7 +352,7 @@ module When::Parts
|
|
341
352
|
# eql? はオーバーライドしない
|
342
353
|
#
|
343
354
|
def self._sort(list, direction)
|
344
|
-
list = list.sort
|
355
|
+
list = (0...list.size).to_a.map {|i| [list[i], i]}.sort.map {|e| e[0]}
|
345
356
|
prev = nil
|
346
357
|
list.delete_if do |x|
|
347
358
|
if (x == prev)
|