when_exe 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,6 +37,13 @@ module When
37
37
  #
38
38
  attr_reader :until
39
39
 
40
+ # オリジナル文字列
41
+ #
42
+ # @return [String]
43
+ #
44
+ attr_accessor :original
45
+ private :original=
46
+
40
47
  # オブジェクトを When::Events::Range 型に変換する
41
48
  #
42
49
  # @param [Object] source 変換元のオブジェクト
@@ -605,10 +612,9 @@ module When
605
612
  # 日時範囲化
606
613
  to_range = proc {|event, date|
607
614
  target = When.when?(date, :parse=>When::Locale::EasternParser)
608
- case target
609
- when Array, Enumerator ; Range.convert_from(target)
610
- else ; target
611
- end
615
+ target = Range.convert_from(target) if target.kind_of?(Array) || target.kind_of?(Enumerator)
616
+ target.send(:original=, date) if target.kind_of?(Range)
617
+ target
612
618
  }
613
619
 
614
620
  # 日付化
@@ -1187,14 +1193,14 @@ module When
1187
1193
  event_range.overlaped(range).each do |focused_date|
1188
1194
  sort_required = true
1189
1195
  focused_event = event.deep_copy
1190
- focused_event.role[VALID] = focused_date
1196
+ focused_event.send(:date=, focused_date)
1191
1197
  narrowed_events << focused_event
1192
1198
  end
1193
1199
  else
1194
1200
  narrowed_events << event
1195
1201
  end
1196
1202
  end
1197
- narrowed_events.sort_by! {|event| event.role[VALID]} if sort_required
1203
+ narrowed_events.sort_by! {|event| event.date} if sort_required
1198
1204
  narrowed_events
1199
1205
  end
1200
1206
 
@@ -1325,37 +1331,42 @@ module When
1325
1331
  source = yield(source) if block_given? && operation !~ /SPARQL|CalendarEra/i
1326
1332
  raise IOError, target + ': not ready' unless source
1327
1333
  for_each_record(source, operation) do |row|
1328
- event = Event.new(self, @events.size+1, row)
1329
- @events << event
1330
-
1331
- @role.keys.each do |item|
1332
- case item
1333
- when LABEL, REFERENCE
1334
- when HAS_PART
1335
- if event.role[HAS_PART].kind_of?(Array)
1336
- event.role[HAS_PART].each do |word|
1337
- @index[HAS_PART][word] << @events.size
1334
+ begin
1335
+ event = Event.new(self, @events.size+1, row)
1336
+ @events << event
1337
+
1338
+ @role.keys.each do |item|
1339
+ case item
1340
+ when LABEL, REFERENCE
1341
+ when HAS_PART
1342
+ if event.role[HAS_PART].kind_of?(Array)
1343
+ event.role[HAS_PART].each do |word|
1344
+ @index[HAS_PART][word] << @events.size
1345
+ end
1346
+ else
1347
+ event.each_word do |word|
1348
+ @index[HAS_PART][word] << @events.size
1349
+ end
1338
1350
  end
1351
+ when WHAT_DAY
1352
+ date = event.role[WHAT_DAY]
1353
+ key = [date.class.to_s !~ /\AWhen/ ||
1354
+ date.frame.kind_of?(When::CalendarTypes::Christian),
1355
+ date.month * 1, date.day]
1356
+ @index[WHAT_DAY][key] << @events.size
1339
1357
  else
1340
- event.each_word do |word|
1341
- @index[HAS_PART][word] << @events.size
1342
- end
1358
+ add_index(:role, item)
1343
1359
  end
1344
- when WHAT_DAY
1345
- date = event.role[WHAT_DAY]
1346
- key = [date.class.to_s !~ /\AWhen/ ||
1347
- date.frame.kind_of?(When::CalendarTypes::Christian),
1348
- date.month * 1, date.day]
1349
- @index[WHAT_DAY][key] << @events.size
1350
- else
1351
- add_index(:role, item)
1352
1360
  end
1353
- end
1354
-
1355
- [:rdf, :csv].each do |method|
1356
- send(method).keys.each do |item|
1357
- add_index(method, item)
1361
+
1362
+ [:rdf, :csv].each do |method|
1363
+ send(method).keys.each do |item|
1364
+ add_index(method, item)
1365
+ end
1358
1366
  end
1367
+ rescue => exception
1368
+ puts "#{source}##{@events.size+1}: #{exception}"
1369
+ # puts exception.backtrace
1359
1370
  end
1360
1371
  end
1361
1372
 
@@ -1660,6 +1671,22 @@ module When
1660
1671
  #
1661
1672
  attr_reader :order
1662
1673
 
1674
+ #
1675
+ # deep copy 時の元イベント
1676
+ #
1677
+ # @return [When::Events::Event]
1678
+ #
1679
+ attr_accessor :original
1680
+ protected :original=
1681
+
1682
+ #
1683
+ # 日付または日付範囲
1684
+ #
1685
+ # @return [When::TM::TemporalPosition or When::Events::Range]
1686
+ #
1687
+ attr_accessor :date
1688
+ private :date=
1689
+
1663
1690
  #
1664
1691
  # HAS_PART対象の文字列中の{}で囲まれた語に対して yield で指定された処理を行う
1665
1692
  #
@@ -1742,6 +1769,13 @@ module When
1742
1769
  words.each do |word|
1743
1770
  @statements << ::RDF::Statement(subject, @dataset.resource[predicate], word)
1744
1771
  end
1772
+ when VALID
1773
+ if object.kind_of?(Range)
1774
+ object = object.original
1775
+ elsif object.respond_to?(:to_uri)
1776
+ object = object.to_uri
1777
+ end
1778
+ @statements << ::RDF::Statement(subject, @dataset.resource[predicate], object)
1745
1779
  # when ABSTRACT
1746
1780
  # @statements << ::RDF::Statement(subject, @dataset.resource[predicate], abstract)
1747
1781
  else
@@ -1765,10 +1799,11 @@ module When
1765
1799
  # @return [When::Events::Event] コピー結果
1766
1800
  #
1767
1801
  def deep_copy
1768
- result = self.dup
1769
- result.csv = @csv.dup
1770
- result.rdf = @rdf.dup
1771
- result.role = @role.dup
1802
+ result = self.dup
1803
+ result.csv = @csv.dup
1804
+ result.rdf = @rdf.dup
1805
+ result.role = @role.dup
1806
+ result.original = self
1772
1807
  result
1773
1808
  end
1774
1809
 
@@ -1831,6 +1866,8 @@ module When
1831
1866
  definition[:operation].call(self, format == '%s' ? fields.first : format % fields)
1832
1867
  end
1833
1868
  end
1869
+
1870
+ @date = @role[VALID]
1834
1871
  end
1835
1872
 
1836
1873
  private
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2015 Takashi SUGA
3
+ Copyright (C) 2011-2016 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
@@ -595,9 +595,10 @@ module When::V
595
595
  end
596
596
  }
597
597
  residue_options = delayed_options[:residue]
598
+ frame_len = base.frame.indices.length
598
599
  if residue_options
599
- event_options['rrule'].update(_byyear(residue_options)) if residue_options[0]
600
- event_options['rrule'].update(_byday(residue_options )) if residue_options[2]
600
+ event_options['rrule'].update(_byyear(residue_options.delete(frame_len-2))) if residue_options[frame_len-2]
601
+ event_options['rrule'].update(_byday(residue_options.delete(frame_len) )) if residue_options[frame_len]
601
602
  delayed_options.delete(:residue)
602
603
  end
603
604
  if base.precision == When::MONTH && event_options['rrule']['FREQ'] == 'YEARLY'
@@ -620,14 +621,13 @@ module When::V
620
621
 
621
622
  # オブジェクト変換オプションの遅延適用のBYYEAR要素
622
623
  #
623
- def _byyear(options)
624
- {'BYYEAR'=>_to_ical_hash(When.Residue(options.delete(0)), 'year', 4)}
624
+ def _byyear(operation)
625
+ {'BYYEAR'=>_to_ical_hash(When.Residue(operation), 'year', 4)}
625
626
  end
626
627
 
627
628
  # オブジェクト変換オプションの遅延適用のBYDAY要素
628
629
  #
629
- def _byday(options)
630
- operation = options.delete(2)
630
+ def _byday(operation)
631
631
  return {'BYDAY'=>_to_ical_hash(operation, 'day', 11)} if operation.kind_of?(When::Coordinates::Residue)
632
632
 
633
633
  residues = []
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2015 Takashi SUGA
3
+ Copyright (C) 2011-2016 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
@@ -773,7 +773,7 @@ module When
773
773
  # @return [String]
774
774
  #
775
775
  def _to_uri(date)
776
- (date.gsub(/\./, '-').gsub(/%/, '@') + caret_frame).
776
+ (date.gsub(/%/, '@').sub(/(\d{2}:\d{2}:\d{2})\.(\d+)/, '\1%2E\2').gsub(/\./, '-') + caret_frame).
777
777
  gsub(When::Parts::Resource::IRIEncode) {|c| When::Parts::Resource::IRIEncodeTable[c]}
778
778
  end
779
779
 
@@ -1460,7 +1460,7 @@ module When
1460
1460
  # 出力に使用する clk_time の作成
1461
1461
  def _clk_time_for_inspect(precision)
1462
1462
  return @clk_time unless precision && precision > When::DAY
1463
- base = self + When::TM::Duration.new(@clk_time.frame._round_value(precision))
1463
+ base = self + When::TM::PeriodDuration.new(0.5, precision)
1464
1464
  base.clk_time.clk_time[When::HOUR] = @clk_time.clk_time[When::HOUR] + 1 unless self.to_i == base.to_i
1465
1465
  return base.clk_time
1466
1466
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2014-2015 Takashi SUGA
3
+ Copyright (C) 2014-2016 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
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2015 Takashi SUGA
3
+ Copyright (C) 2011-2016 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
@@ -373,9 +373,21 @@ module When::Parts
373
373
  end
374
374
  end
375
375
  case @_pool[iri]
376
- when my_mutex; my_mutex.synchronize {@_pool[iri] = _create_object(iri, path, query, &block) }
377
- when Mutex ; @_pool[iri].synchronize {@_pool[iri]}
378
- else ; @_pool[iri]
376
+ when my_mutex
377
+ my_mutex.synchronize do
378
+ begin
379
+ @_pool[iri] = _create_object(iri, path, query, &block)
380
+ rescue => exception
381
+ @_pool[iri] = nil
382
+ raise exception
383
+ end
384
+ end
385
+ when Mutex
386
+ @_pool[iri].synchronize do
387
+ @_pool[iri]
388
+ end
389
+ else
390
+ @_pool[iri]
379
391
  end
380
392
  else
381
393
  @_pool ||= {}
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2015 Takashi SUGA
3
+ Copyright (C) 2011-2016 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
@@ -16,7 +16,7 @@ module When::Parts
16
16
  class Timezone
17
17
 
18
18
  #
19
- # When::V::Timezone と Qhwn::Parts::Timezone の抽象基底
19
+ # When::TM::Clock, When::V::Timezone と Qhwn::Parts::Timezone の抽象基底
20
20
  #
21
21
  module Base
22
22
  # 標準時間帯の時計
@@ -39,10 +39,13 @@ module When::Parts
39
39
  # @return [When::TM::DateAndTime, When::TM::JulianDate]
40
40
  #
41
41
  def ^(date, options={})
42
- date = When::TM::Position.any_other(date, options)
43
- options = date._attr.merge({:clock=>self}).merge(options)
44
- return When::TM::JulianDate.dynamical_time(date.dynamical_time, options) unless date.frame.kind_of?(When::TM::Calendar)
45
- date.frame.jul_trans(When::TM::JulianDate.dynamical_time(date.dynamical_time), options)
42
+ date = When::TM::Position.any_other(date, options)
43
+ my_opt = date._attr
44
+ my_opt[:clock] = self
45
+ my_opt[:time_standard] = time_standard if respond_to?(:time_standard)
46
+ my_opt.merge(options)
47
+ return When::TM::JulianDate.dynamical_time(date.dynamical_time, my_opt) unless date.frame.kind_of?(When::TM::Calendar)
48
+ date.frame.jul_trans(When::TM::JulianDate.dynamical_time(date.dynamical_time, {:time_standard=>my_opt[:time_standard]}), my_opt)
46
49
  end
47
50
  end
48
51
 
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2015 Takashi SUGA
3
+ Copyright (C) 2011-2016 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
@@ -820,7 +820,8 @@ module When
820
820
  #
821
821
  def _normalize(args=[], options={})
822
822
  @label ||= 'Chinese::ChineseSolar'
823
- @formula ||= ['Formula']
823
+ @formula ||= (When::CalendarNote::LuniSolarPositions.table_off ? ['Formula'] :
824
+ [When.Resource('_ep:SolarFormulaWithTable'), When.Resource('_ep:LunarFormulaWithTable')])
824
825
  @formula = Array(@formula)
825
826
  @formula *= 2 if @formula.length == 1
826
827
  @formula[0] += (@formula[0] =~ /\?/ ? '&' : '?') + 'formula=12S' if @formula[0].kind_of?(String)
@@ -873,7 +874,8 @@ module When
873
874
  #
874
875
  def _normalize(args=[], options={})
875
876
  @label ||= 'Chinese::ChineseLuniSolar'
876
- @formula ||= ['Formula']
877
+ @formula ||= (When::CalendarNote::LuniSolarPositions.table_off ? ['Formula'] :
878
+ [When.Resource('_ep:SolarFormulaWithTable'), When.Resource('_ep:LunarFormulaWithTable')])
877
879
  @formula = Array(@formula)
878
880
  @formula *= 2 if @formula.length == 1
879
881
  @formula[0] += (@formula[0] =~ /\?/ ? '&' : '?') + 'formula=12S' if @formula[0].kind_of?(String)
@@ -635,8 +635,8 @@ module When
635
635
  def _new_month_(m)
636
636
  new_month_time = @formula[0].cn_to_time(m + @cycle_offset)
637
637
  new_month_date = (new_month_time + 0.5 + @formula[0].long/360.0).floor
638
- sunrise_time = @formula[0].sunrise(new_month_date)
639
- (sunrise_time <= new_month_time) ? new_month_date : new_month_date-1
638
+ # sunrise_time = @formula[0].sunrise(new_month_date)
639
+ # (sunrise_time <= new_month_time) ? new_month_date : new_month_date-1
640
640
  end
641
641
 
642
642
  private
@@ -1271,7 +1271,10 @@ class When::CalendarNote
1271
1271
  2396063 => [315.0, 1], # 弘化05(1848).01.01 [315.0, 0] 没
1272
1272
 
1273
1273
  2397583 => [ 15.0, 1], # 嘉永05(1852).02=15 [ 14.0, 0] 没
1274
- 2397584 => [ 16.0, 0] # 嘉永05(1852).02=16 [ 15.0, 1] 清明 (計算誤差の補正)
1274
+ 2397584 => [ 16.0, 0], # 嘉永05(1852).02=16 [ 15.0, 1] 清明 (計算誤差の補正)
1275
+
1276
+ 2451110 => [210.0, 1], # 平成10(1998).10.23 [209.0, 0] 没
1277
+ 2451111 => [211.0, 0] # 平成10(1998).10.24 [210.0, 1] 霜降 (計算誤差の補正)
1275
1278
  }
1276
1279
 
1277
1280
  class << self
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2015 Takashi SUGA
3
+ Copyright (C) 2011-2016 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
@@ -372,9 +372,14 @@ module When::TM
372
372
  d
373
373
  }
374
374
 
375
+ # 繰り返しの起点と間隔
376
+ base = element[0].kind_of?(Duration) ? element[1] : element[0]
377
+ frame_len = (base.respond_to?(:frame) ? base.frame : When::Gregorian).indices.length
378
+ duration = _duration_for_repeat(element)
379
+
375
380
  # 意味のある繰り返しのない場合
376
- has_residue_options = delayed_options[:residue] && (delayed_options[:residue][0].kind_of?(String) ||
377
- delayed_options[:residue][2].kind_of?(String))
381
+ has_residue_options = delayed_options[:residue] && (delayed_options[:residue][frame_len-2].kind_of?(String) ||
382
+ delayed_options[:residue][frame_len].kind_of?(String))
378
383
  case repeat
379
384
  when nil ; return _instance_without_repeat(element).apply_delayed_options(delayed_options) unless has_residue_options
380
385
  when 0 ; return []
@@ -383,10 +388,6 @@ module When::TM
383
388
  raise ArgumentError, "Duration or TemporalPosition missing" unless element[1] || has_residue_options
384
389
  end
385
390
 
386
- # 繰り返しの起点と間隔
387
- base = element[0].kind_of?(Duration) ? element[1] : element[0]
388
- duration = _duration_for_repeat(element)
389
-
390
391
  # 繰り返しのある場合
391
392
  if repeat.kind_of?(Integer) && !has_residue_options
392
393
 
@@ -408,7 +409,8 @@ module When::TM
408
409
  return duration.set_repeat(true) unless base
409
410
 
410
411
  # iCalendar の機能を使用する
411
- should_limit = base.precision == When::MONTH && !(delayed_options[:residue] && delayed_options[:residue][0])
412
+ should_limit = base.precision == When::MONTH &&
413
+ !(delayed_options[:residue] && delayed_options[:residue][frame_len-2])
412
414
  iterator = When::V::Event.iterator_for_ISO8601(base, duration, delayed_options)
413
415
  case repeat
414
416
  when nil ; (result=iterator.succ).precision > base.precision && should_limit && base != result ? nil : result
@@ -430,6 +432,7 @@ module When::TM
430
432
  options = TemporalPosition._options(options)
431
433
  options[:frame] ||= 'Gregorian'
432
434
  options[:frame] = When.Resource(options[:frame], '_c:') if options[:frame].kind_of?(String)
435
+ frame_len = options[:frame].indices.length
433
436
  case args[0]
434
437
  when String
435
438
  options[:era_name] = When::EncodingConversion.to_internal_encoding(args.shift)
@@ -441,7 +444,7 @@ module When::TM
441
444
  # 時間位置の生成
442
445
  res = []
443
446
  abbrs = Array(options[:abbr])
444
- date = Array.new(options[:frame].indices.length-1) {
447
+ date = Array.new(frame_len-1) {
445
448
  element = args.shift
446
449
  abbr = abbrs.shift
447
450
  res << element.to('year') if element.kind_of?(When::Coordinates::Residue)
@@ -458,8 +461,8 @@ module When::TM
458
461
  end
459
462
  }
460
463
  parse = options.delete(:parse)
461
- if parse && parse[:residue] && parse[:residue][2]
462
- res << parse[:residue][2]
464
+ if parse && parse[:residue] && parse[:residue][frame_len]
465
+ res << parse[:residue][frame_len]
463
466
  end
464
467
  if args.length > 0
465
468
  options[:clock] ||= Clock.local_time
@@ -838,8 +841,10 @@ module When::TM
838
841
  else ; raise TypeError, "The right operand should be Numeric or Duration"
839
842
  end
840
843
  return _plus(other) if other.kind_of?(PeriodDuration)
841
- @frame.kind_of?(Calendar) ? @frame.jul_trans(JulianDate.dynamical_time(dynamical_time + other.duration), self._attr) :
842
- JulianDate.dynamical_time(dynamical_time + other.duration, self._attr)
844
+ options = self._attr
845
+ time = dynamical_time + other.duration
846
+ @frame.kind_of?(Calendar) ? @frame.jul_trans(JulianDate.dynamical_time(time, {:time_standard=>options[:time_standard]}), options) :
847
+ JulianDate.dynamical_time(time, options)
843
848
  rescue RangeError
844
849
  (@frame ^ self) + other
845
850
  end
@@ -863,8 +868,10 @@ module When::TM
863
868
  else ; raise TypeError, "The right operand should be Numeric, Duration or TemporalPosition"
864
869
  end
865
870
  return _plus(-other) if other.kind_of?(PeriodDuration)
866
- @frame.kind_of?(Calendar) ? @frame.jul_trans(JulianDate.dynamical_time(dynamical_time - other.duration), self._attr) :
867
- JulianDate.dynamical_time(dynamical_time - other.duration, self._attr)
871
+ options = self._attr
872
+ time = dynamical_time - other.duration
873
+ @frame.kind_of?(Calendar) ? @frame.jul_trans(JulianDate.dynamical_time(time, {:time_standard=>options[:time_standard]}), options) :
874
+ JulianDate.dynamical_time(time, options)
868
875
  rescue RangeError
869
876
  (@frame ^ self) - other
870
877
  end
@@ -1065,12 +1072,13 @@ module When::TM
1065
1072
  # @return [When::TM::TemporalPosition]
1066
1073
  #
1067
1074
  def apply_delayed_options(options)
1068
- position = self
1075
+ position = self
1076
+ frame_len = frame.indices.length
1069
1077
  if options[:residue]
1070
1078
  options[:residue].keys.sort.each do |count|
1071
1079
  options[:residue][count] = When.Residue(options[:residue][count]) unless options[:residue][count].kind_of?(When::Coordinates::Residue)
1072
1080
  residue = options[:residue][count]
1073
- if count == 0
1081
+ if count == frame_len - 2
1074
1082
  residue = residue.to('year')
1075
1083
  position &= residue
1076
1084
  else