zakuro 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +6 -4
  4. data/VERSION +1 -1
  5. data/doc/operation/transfer.rb +8 -8
  6. data/lib/zakuro/calculation/base/gengou.rb +46 -0
  7. data/lib/zakuro/calculation/era/gengou/{scroll.rb → abstract_scroll.rb} +6 -8
  8. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  9. data/lib/zakuro/calculation/era/gengou/internal/reserve/{list.rb → abstract_list.rb} +37 -51
  10. data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +17 -17
  11. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  12. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  13. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
  14. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +2 -3
  17. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  18. data/lib/zakuro/calculation/monthly/month.rb +39 -0
  19. data/lib/zakuro/calculation/monthly/operated_month.rb +1 -1
  20. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +5 -4
  21. data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +9 -11
  22. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  23. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  24. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  25. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  26. data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -2
  27. data/lib/zakuro/calculation/{specifier → summary}/internal/month.rb +1 -1
  28. data/lib/zakuro/calculation/summary/japan/range.rb +152 -0
  29. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  30. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +91 -0
  31. data/lib/zakuro/calculation/summary/western/range.rb +124 -0
  32. data/lib/zakuro/calculation/summary/western/single.rb +113 -0
  33. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +169 -0
  34. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +93 -0
  35. data/lib/zakuro/condition.rb +1 -2
  36. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +89 -74
  37. data/lib/zakuro/era/japan/gengou/alignment/division.rb +125 -122
  38. data/lib/zakuro/era/japan/gengou/alignment/line.rb +141 -122
  39. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +171 -168
  40. data/lib/zakuro/era/japan/gengou/alignment.rb +38 -25
  41. data/lib/zakuro/era/japan/gengou/resource/parser.rb +183 -182
  42. data/lib/zakuro/era/japan/gengou/resource/type.rb +233 -232
  43. data/lib/zakuro/era/japan/gengou/resource/validator.rb +255 -254
  44. data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
  45. data/lib/zakuro/era/japan/gengou.rb +5 -20
  46. data/lib/zakuro/era/western/calendar.rb +9 -9
  47. data/lib/zakuro/exception/case/pattern.rb +35 -0
  48. data/lib/zakuro/exception/case/preset.rb +51 -0
  49. data/lib/zakuro/exception/case/template.rb +48 -0
  50. data/lib/zakuro/exception/cause.rb +28 -0
  51. data/lib/zakuro/exception/exception.rb +37 -0
  52. data/lib/zakuro/exception/zakuro_error.rb +28 -0
  53. data/lib/zakuro/gateway/locale/date.rb +127 -0
  54. data/lib/zakuro/gateway/locale/range.rb +67 -0
  55. data/lib/zakuro/gateway/range.rb +99 -0
  56. data/lib/zakuro/gateway/single.rb +70 -0
  57. data/lib/zakuro/merchant.rb +8 -44
  58. data/lib/zakuro/operation/month/parser.rb +9 -9
  59. data/lib/zakuro/operation/month/type.rb +31 -31
  60. data/lib/zakuro/operation/month/validator.rb +49 -49
  61. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  62. data/lib/zakuro/output/logger.rb +17 -3
  63. data/lib/zakuro/result/data/day.rb +43 -0
  64. data/lib/zakuro/result/data/gengou.rb +35 -0
  65. data/lib/zakuro/result/data/month.rb +63 -0
  66. data/lib/zakuro/result/data/single_day.rb +48 -0
  67. data/lib/zakuro/result/data/solar_term.rb +35 -0
  68. data/lib/zakuro/result/data/year.rb +45 -0
  69. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  70. data/lib/zakuro/result/operation/month/bundle.rb +36 -0
  71. data/lib/zakuro/result/operation/month/history.rb +54 -0
  72. data/lib/zakuro/result/operation/operation.rb +44 -0
  73. data/lib/zakuro/result/result.rb +4 -2
  74. metadata +46 -14
  75. data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
  76. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  77. data/lib/zakuro/calculation/summary/range.rb +0 -120
  78. data/lib/zakuro/calculation/summary/single.rb +0 -110
  79. data/lib/zakuro/result/data.rb +0 -187
  80. data/lib/zakuro/result/operation.rb +0 -114
@@ -1,10 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './era/western/calendar'
3
+ require_relative './gateway/single'
4
4
 
5
- require_relative './calculation/summary/single'
6
-
7
- require_relative './calculation/summary/range'
5
+ require_relative './gateway/range'
8
6
 
9
7
  require_relative './condition'
10
8
 
@@ -55,52 +53,18 @@ module Zakuro
55
53
  # @return [Result::Range] 和暦日範囲
56
54
  #
57
55
  def commit
58
- date = condition.date
59
-
60
- return single(date: date) if date
61
-
62
- range = condition.range
63
-
64
- return range(range: range) if range
65
-
66
- {}
67
- end
68
-
69
- private
70
-
71
- #
72
- # 1日検索
73
- #
74
- # @param [Date] date 西暦日
75
- #
76
- # @return [Result::Single] 検索結果
77
- #
78
- def single(date:)
79
- western_date = Western::Calendar.create(date: date)
80
-
81
56
  # TODO: condition で設定する
82
57
  context = Context.new(version_name: '')
83
58
 
84
- Calculation::Summary::Single.get(context: context, date: western_date)
85
- end
59
+ single = Gateway::Single.new(context: context, date: condition.date)
86
60
 
87
- #
88
- # 期間検索
89
- #
90
- # @param [Catalog::Range] range 期間
91
- #
92
- # @return [Result::Range] 和暦日範囲
93
- #
94
- def range(range:)
95
- start_date = Western::Calendar.create(date: range[:start])
96
- last_date = Western::Calendar.create(date: range[:last])
61
+ return single.get unless single.invalid?
97
62
 
98
- # TODO: condition で設定する
99
- context = Context.new(version_name: '')
63
+ range = Gateway::Range.new(context: context, range: condition.range)
64
+
65
+ return range.get unless range.invalid?
100
66
 
101
- Calculation::Summary::Range.get(
102
- context: context, start_date: start_date, last_date: last_date
103
- )
67
+ {}
104
68
  end
105
69
  end
106
70
  end
@@ -80,7 +80,7 @@ module Zakuro
80
80
  def self.western_date(str:)
81
81
  return Western::Calendar.new if invalid?(str: str)
82
82
 
83
- Western::Calendar.parse(str: str)
83
+ Western::Calendar.parse(text: str)
84
84
  end
85
85
 
86
86
  #
@@ -311,8 +311,8 @@ module Zakuro
311
311
 
312
312
  def self.create_solar_term(yaml_hash: {})
313
313
  SolarTerm::Direction.new(
314
- source: create_source_solar_term(yaml_hash: yaml_hash['calc']),
315
- destination: create_destination_solar_term(yaml_hash: yaml_hash['actual']),
314
+ source: create_source_solar_term(yaml_hash: yaml_hash['src']),
315
+ destination: create_destination_solar_term(yaml_hash: yaml_hash['dest']),
316
316
  days: Operation::TypeParser.days(str: yaml_hash['days'])
317
317
  )
318
318
  end
@@ -347,24 +347,24 @@ module Zakuro
347
347
 
348
348
  def self.create_month_number(yaml_hash: {})
349
349
  Number.new(
350
- calc: Operation::TypeParser.month_number(str: yaml_hash['calc']),
351
- actual: Operation::TypeParser.month_number(str: yaml_hash['actual'])
350
+ src: Operation::TypeParser.month_number(str: yaml_hash['src']),
351
+ dest: Operation::TypeParser.month_number(str: yaml_hash['dest'])
352
352
  )
353
353
  end
354
354
  private_class_method :create_month_number
355
355
 
356
356
  def self.create_month_leaped(yaml_hash: {})
357
357
  Leaped.new(
358
- calc: Operation::TypeParser.month_leaped(str: yaml_hash['calc']),
359
- actual: Operation::TypeParser.month_leaped(str: yaml_hash['actual'])
358
+ src: Operation::TypeParser.month_leaped(str: yaml_hash['src']),
359
+ dest: Operation::TypeParser.month_leaped(str: yaml_hash['dest'])
360
360
  )
361
361
  end
362
362
  private_class_method :create_month_leaped
363
363
 
364
364
  def self.create_month_day(yaml_hash: {})
365
365
  Days.new(
366
- calc: yaml_hash['calc'],
367
- actual: yaml_hash['actual']
366
+ src: yaml_hash['src'],
367
+ dest: yaml_hash['dest']
368
368
  )
369
369
  end
370
370
  private_class_method :create_month_day
@@ -339,20 +339,20 @@ module Zakuro
339
339
  # Number 月
340
340
  #
341
341
  class Number
342
- # @return [Integer] 計算
343
- attr_reader :calc
344
- # @return [Integer] 運用
345
- attr_reader :actual
342
+ # @return [Integer] 移動もと
343
+ attr_reader :src
344
+ # @return [Integer] 移動先
345
+ attr_reader :dest
346
346
 
347
347
  #
348
348
  # 初期化
349
349
  #
350
- # @param [Integer] calc 計算
351
- # @param [Integer] actual 運用
350
+ # @param [Integer] src 移動元
351
+ # @param [Integer] dest 移動先
352
352
  #
353
- def initialize(calc: -1, actual: -1)
354
- @calc = calc
355
- @actual = actual
353
+ def initialize(src: -1, dest: -1)
354
+ @src = src
355
+ @dest = dest
356
356
  end
357
357
 
358
358
  #
@@ -362,7 +362,7 @@ module Zakuro
362
362
  # @return [False] 有効
363
363
  #
364
364
  def invalid?
365
- @calc == -1 || @actual == -1
365
+ @src == -1 || @dest == -1
366
366
  end
367
367
 
368
368
  #
@@ -381,7 +381,7 @@ module Zakuro
381
381
  # @return [Integer] 間隔
382
382
  #
383
383
  def interval
384
- @calc - @actual
384
+ @src - @dest
385
385
  end
386
386
 
387
387
  #
@@ -428,22 +428,22 @@ module Zakuro
428
428
  # Leaped 閏有無
429
429
  #
430
430
  class Leaped
431
- # @return [True, False] 計算
432
- attr_reader :calc
433
- # @return [True, False] 運用
434
- attr_reader :actual
431
+ # @return [True, False] 移動元
432
+ attr_reader :src
433
+ # @return [True, False] 移動先
434
+ attr_reader :dest
435
435
 
436
436
  # :reek:BooleanParameter
437
437
 
438
438
  #
439
439
  # 初期化
440
440
  #
441
- # @param [True, False] calc 計算
442
- # @param [True, False] actual 運用
441
+ # @param [True, False] src 移動元
442
+ # @param [True, False] dest 移動先
443
443
  #
444
- def initialize(calc: false, actual: false)
445
- @calc = calc
446
- @actual = actual
444
+ def initialize(src: false, dest: false)
445
+ @src = src
446
+ @dest = dest
447
447
  end
448
448
 
449
449
  #
@@ -453,7 +453,7 @@ module Zakuro
453
453
  # @return [False] 有効
454
454
  #
455
455
  def invalid?
456
- !@calc && !@actual
456
+ !@src && !@dest
457
457
  end
458
458
  end
459
459
 
@@ -469,12 +469,12 @@ module Zakuro
469
469
  #
470
470
  # 初期化
471
471
  #
472
- # @param [String] calc 計算
473
- # @param [String] actual 運用
472
+ # @param [String] src 移動元
473
+ # @param [String] dest 移動先
474
474
  #
475
- def initialize(calc: '小', actual: '小')
476
- @calc = calc
477
- @actual = actual
475
+ def initialize(src: '小', dest: '小')
476
+ @src = src
477
+ @dest = dest
478
478
  end
479
479
 
480
480
  #
@@ -483,8 +483,8 @@ module Zakuro
483
483
  # @return [True] 大
484
484
  # @return [False] 小
485
485
  #
486
- def calc
487
- @calc == BIG
486
+ def src
487
+ @src == BIG
488
488
  end
489
489
 
490
490
  #
@@ -493,8 +493,8 @@ module Zakuro
493
493
  # @return [True] 大
494
494
  # @return [False] 小
495
495
  #
496
- def actual
497
- @actual == BIG
496
+ def dest
497
+ @dest == BIG
498
498
  end
499
499
 
500
500
  #
@@ -504,7 +504,7 @@ module Zakuro
504
504
  # @return [False] 有効
505
505
  #
506
506
  def invalid?
507
- @calc == @actual
507
+ @src == @dest
508
508
  end
509
509
  end
510
510
  end
@@ -135,7 +135,7 @@ module Zakuro
135
135
  def self.western_date?(str: '')
136
136
  return Western::Calendar.new if str == EMPTY_STRING
137
137
 
138
- Western::Calendar.valid_date_string(str: str)
138
+ Western::Calendar.valid_date_string(text: str)
139
139
  end
140
140
  end
141
141
 
@@ -461,14 +461,14 @@ module Zakuro
461
461
  #
462
462
  # @param [Integer] index 連番
463
463
  # @param [Hash<String, Object>] yaml_hash yaml
464
- # @option yaml_hash [Hash] :calc 移動元
465
- # @option yaml_hash [Hash] :actual 移動先
464
+ # @option yaml_hash [Hash] :src 移動元
465
+ # @option yaml_hash [Hash] :dest 移動先
466
466
  # @option yaml_hash [String] :days 中気差分
467
467
  #
468
468
  def initialize(index:, yaml_hash: {})
469
469
  @index = index
470
- @source = Source.new(diff_index: index, yaml_hash: yaml_hash['calc'])
471
- @destination = Destination.new(diff_index: index, yaml_hash: yaml_hash['actual'])
470
+ @source = Source.new(diff_index: index, yaml_hash: yaml_hash['src'])
471
+ @destination = Destination.new(diff_index: index, yaml_hash: yaml_hash['dest'])
472
472
  @days = yaml_hash['days']
473
473
  end
474
474
 
@@ -537,7 +537,7 @@ module Zakuro
537
537
  def validate
538
538
  failed = []
539
539
 
540
- prefix = "[#{@diff_index}][solar_term.calc] invalid"
540
+ prefix = "[#{@diff_index}][solar_term.src] invalid"
541
541
 
542
542
  failed.push("#{prefix} 'index'. #{@index}") unless index?
543
543
 
@@ -600,7 +600,7 @@ module Zakuro
600
600
  def validate
601
601
  failed = []
602
602
 
603
- prefix = "[#{@diff_index}][solar_term.actual] invalid"
603
+ prefix = "[#{@diff_index}][solar_term.dest] invalid"
604
604
 
605
605
  failed.push("#{prefix} 'index'. #{@index}") unless index?
606
606
 
@@ -633,23 +633,23 @@ module Zakuro
633
633
 
634
634
  # @return [Integer] 連番
635
635
  attr_reader :index
636
- # @return [String] 計算
637
- attr_reader :calc
638
- # @return [String] 運用
639
- attr_reader :actual
636
+ # @return [String] 移動元
637
+ attr_reader :src
638
+ # @return [String] 移動先
639
+ attr_reader :dest
640
640
 
641
641
  #
642
642
  # 初期化
643
643
  #
644
644
  # @param [Integer] index 連番
645
645
  # @param [Hash<String, String>] yaml_hash yaml
646
- # @option yaml_hash [String] :calc 計算
647
- # @option yaml_hash [String] :actual 運用
646
+ # @option yaml_hash [String] :src 移動元
647
+ # @option yaml_hash [String] :dest 移動先
648
648
  #
649
649
  def initialize(index:, yaml_hash: {})
650
650
  @index = index
651
- @calc = yaml_hash['calc']
652
- @actual = yaml_hash['actual']
651
+ @src = yaml_hash['src']
652
+ @dest = yaml_hash['dest']
653
653
  end
654
654
 
655
655
  #
@@ -662,19 +662,19 @@ module Zakuro
662
662
 
663
663
  prefix = "[#{@index}][#{NAME}] invalid"
664
664
 
665
- failed.push("#{prefix} 'calc'. #{@calc}") unless calc?
665
+ failed.push("#{prefix} 'src'. #{@src}") unless src?
666
666
 
667
- failed.push("#{prefix} 'actual'. #{@actual}") unless actual?
667
+ failed.push("#{prefix} 'dest'. #{@dest}") unless dest?
668
668
 
669
669
  failed
670
670
  end
671
671
 
672
- def calc?
673
- Types.positive?(str: @calc)
672
+ def src?
673
+ Types.positive?(str: @src)
674
674
  end
675
675
 
676
- def actual?
677
- Types.positive?(str: @actual)
676
+ def dest?
677
+ Types.positive?(str: @dest)
678
678
  end
679
679
  end
680
680
 
@@ -686,23 +686,23 @@ module Zakuro
686
686
 
687
687
  # @return [Integer] 連番
688
688
  attr_reader :index
689
- # @return [String] 計算
690
- attr_reader :calc
691
- # @return [String] 運用
692
- attr_reader :actual
689
+ # @return [String] 移動元
690
+ attr_reader :src
691
+ # @return [String] 移動先
692
+ attr_reader :dest
693
693
 
694
694
  #
695
695
  # 初期化
696
696
  #
697
697
  # @param [Integer] index 連番
698
698
  # @param [Hash<String, String>] yaml_hash yaml
699
- # @option yaml_hash [String] :calc 計算
700
- # @option yaml_hash [String] :actual 運用
699
+ # @option yaml_hash [String] :src 移動元
700
+ # @option yaml_hash [String] :dest 移動先
701
701
  #
702
702
  def initialize(index:, yaml_hash: {})
703
703
  @index = index
704
- @calc = yaml_hash['calc']
705
- @actual = yaml_hash['actual']
704
+ @src = yaml_hash['src']
705
+ @dest = yaml_hash['dest']
706
706
  end
707
707
 
708
708
  #
@@ -715,19 +715,19 @@ module Zakuro
715
715
 
716
716
  prefix = "[#{@index}][#{NAME}] invalid"
717
717
 
718
- failed.push("#{prefix} 'calc'. #{@calc}") unless calc?
718
+ failed.push("#{prefix} 'src'. #{@src}") unless src?
719
719
 
720
- failed.push("#{prefix} 'actual'. #{@actual}") unless actual?
720
+ failed.push("#{prefix} 'dest'. #{@dest}") unless dest?
721
721
 
722
722
  failed
723
723
  end
724
724
 
725
- def calc?
726
- Types.empiable_bool?(str: @calc)
725
+ def src?
726
+ Types.empiable_bool?(str: @src)
727
727
  end
728
728
 
729
- def actual?
730
- Types.empiable_bool?(str: @actual)
729
+ def dest?
730
+ Types.empiable_bool?(str: @dest)
731
731
  end
732
732
  end
733
733
 
@@ -739,23 +739,23 @@ module Zakuro
739
739
 
740
740
  # @return [Integer] 連番
741
741
  attr_reader :index
742
- # @return [String] 計算
743
- attr_reader :calc
744
- # @return [String] 運用
745
- attr_reader :actual
742
+ # @return [String] 移動元
743
+ attr_reader :src
744
+ # @return [String] 移動先
745
+ attr_reader :dest
746
746
 
747
747
  #
748
748
  # 初期化
749
749
  #
750
750
  # @param [Integer] index 連番
751
751
  # @param [Hash<String, String>] yaml_hash yaml
752
- # @option yaml_hash [String] :calc 計算
753
- # @option yaml_hash [String] :actual 運用
752
+ # @option yaml_hash [String] :src 移動元
753
+ # @option yaml_hash [String] :dest 移動先
754
754
  #
755
755
  def initialize(index:, yaml_hash: {})
756
756
  @index = index
757
- @calc = yaml_hash['calc']
758
- @actual = yaml_hash['actual']
757
+ @src = yaml_hash['src']
758
+ @dest = yaml_hash['dest']
759
759
  end
760
760
 
761
761
  #
@@ -768,19 +768,19 @@ module Zakuro
768
768
 
769
769
  prefix = "[#{@index}][#{NAME}] invalid"
770
770
 
771
- failed.push("#{prefix} 'calc'. #{@calc}") unless calc?
771
+ failed.push("#{prefix} 'src'. #{@src}") unless src?
772
772
 
773
- failed.push("#{prefix} 'actual'. #{@actual}") unless actual?
773
+ failed.push("#{prefix} 'dest'. #{@dest}") unless dest?
774
774
 
775
775
  failed
776
776
  end
777
777
 
778
- def calc?
779
- Types.month_days?(str: @calc)
778
+ def src?
779
+ Types.month_days?(str: @src)
780
780
  end
781
781
 
782
- def actual?
783
- Types.month_days?(str: @actual)
782
+ def dest?
783
+ Types.month_days?(str: @dest)
784
784
  end
785
785
  end
786
786