zakuro 0.4.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -3
  3. data/VERSION +1 -0
  4. data/doc/operation/csv/month.csv +21 -0
  5. data/doc/operation/operation.xlsx +0 -0
  6. data/lib/zakuro/calculation/base/gengou.rb +82 -0
  7. data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
  8. data/lib/zakuro/calculation/base/operated_year.rb +5 -15
  9. data/lib/zakuro/calculation/base/year.rb +26 -14
  10. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +0 -13
  11. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
  12. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
  13. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
  14. data/lib/zakuro/calculation/era/gengou/internal/reserve/list.rb +244 -0
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/range.rb +193 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +42 -0
  17. data/lib/zakuro/calculation/era/gengou/scroll.rb +211 -0
  18. data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
  19. data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
  20. data/lib/zakuro/calculation/era/version/version.rb +24 -0
  21. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  22. data/lib/zakuro/calculation/monthly/month.rb +49 -2
  23. data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
  24. data/lib/zakuro/calculation/range/full_range.rb +68 -107
  25. data/lib/zakuro/calculation/range/operated_range.rb +13 -9
  26. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
  27. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  28. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  29. data/lib/zakuro/calculation/specifier/internal/month.rb +84 -0
  30. data/lib/zakuro/calculation/specifier/multiple_day.rb +162 -0
  31. data/lib/zakuro/calculation/specifier/single_day.rb +15 -37
  32. data/lib/zakuro/calculation/summary/internal/operation.rb +98 -0
  33. data/lib/zakuro/calculation/summary/range.rb +120 -0
  34. data/lib/zakuro/calculation/summary/single.rb +45 -64
  35. data/lib/zakuro/condition.rb +14 -0
  36. data/lib/zakuro/era/japan/calendar.rb +133 -0
  37. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +106 -0
  38. data/lib/zakuro/era/japan/gengou/alignment/division.rb +165 -0
  39. data/lib/zakuro/era/japan/gengou/alignment/line.rb +156 -0
  40. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +184 -0
  41. data/lib/zakuro/era/japan/gengou/alignment.rb +42 -0
  42. data/lib/zakuro/era/japan/gengou/resource/parser.rb +242 -0
  43. data/lib/zakuro/era/japan/gengou/resource/type.rb +292 -0
  44. data/lib/zakuro/era/japan/gengou/resource/validator.rb +346 -0
  45. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
  46. data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
  47. data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
  48. data/lib/zakuro/era/japan/gengou/resource.rb +32 -0
  49. data/lib/zakuro/era/japan/gengou.rb +35 -74
  50. data/lib/zakuro/era/japan/version.rb +151 -0
  51. data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
  52. data/lib/zakuro/merchant.rb +50 -3
  53. data/lib/zakuro/operation/month/parser.rb +1 -1
  54. data/lib/zakuro/operation/month/type.rb +1 -1
  55. data/lib/zakuro/operation/month/validator.rb +2 -2
  56. data/lib/zakuro/operation/yaml/month.yaml +672 -0
  57. data/lib/zakuro/output/response.rb +5 -5
  58. data/lib/zakuro/result/result.rb +17 -0
  59. data/lib/zakuro/tools/typeconv.rb +38 -0
  60. data/lib/zakuro/tools/typeof.rb +4 -1
  61. data/lib/zakuro/version/context.rb +24 -3
  62. data/lib/zakuro/version/daien/cycle/remainder.rb +26 -0
  63. data/lib/zakuro/version/daien/daien.rb +1 -26
  64. data/lib/zakuro/version/daien/stella/solar/average.rb +2 -2
  65. data/lib/zakuro/version/genka/const/number.rb +43 -0
  66. data/lib/zakuro/version/genka/const/remainder.rb +33 -0
  67. data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
  68. data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
  69. data/lib/zakuro/version/genka/genka.rb +1 -9
  70. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
  71. data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
  72. data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
  73. data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
  74. data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
  75. data/lib/zakuro/version/gihou/cycle/remainder.rb +26 -0
  76. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  77. data/lib/zakuro/version/gihou/stella/solar/average.rb +2 -2
  78. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  79. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  80. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  81. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  82. data/lib/zakuro/version/senmyou/README.md +11 -7
  83. data/lib/zakuro/version/senmyou/cycle/remainder.rb +26 -0
  84. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  85. data/lib/zakuro/version/senmyou/stella/solar/average.rb +2 -2
  86. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  87. data/lib/zakuro/version/version_class_resolver.rb +4 -0
  88. data/zakuro.gemspec +1 -3
  89. metadata +45 -16
  90. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  91. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  92. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  93. data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
  94. data/lib/zakuro/era/japan/gengou/type.rb +0 -178
  95. data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
  96. data/lib/zakuro/era/japan/reki.rb +0 -91
  97. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  98. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  99. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  100. data/lib/zakuro/version/abstract_version.rb +0 -29
  101. data/lib/zakuro/version.rb +0 -7
  102. data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../base/year'
4
+
5
+ require_relative '../../era/western/calendar'
6
+ require_relative '../../output/response'
7
+ require_relative '../../output/logger'
8
+
9
+ require_relative './internal/month'
10
+
11
+ # :nodoc:
12
+ module Zakuro
13
+ # :nodoc:
14
+ module Calculation
15
+ # :nodoc:
16
+ module Specifier
17
+ #
18
+ # MultipleDay 複数日検索
19
+ #
20
+ module MultipleDay
21
+ # @return [Output::Logger] ロガー
22
+ LOGGER = Output::Logger.new(location: 'specifier')
23
+
24
+ #
25
+ # 取得する
26
+ #
27
+ # @param [Array<Base::Year>] years 範囲
28
+ # @param [Western::Calendar] start_date 西暦開始日
29
+ # @param [Western::Calendar] last_date 西暦終了日
30
+ #
31
+ # @return [Array<Result::Data::SingleDay>] 期間検索結果(和暦日)
32
+ #
33
+ def self.get(years: [], start_date: Western::Calendar.new, last_date: Western::Calendar.new)
34
+ months = specify(years: years, start_date: start_date, last_date: last_date)
35
+
36
+ result = []
37
+ months.each do |month|
38
+ result |= month.get
39
+ end
40
+
41
+ result
42
+ end
43
+
44
+ #
45
+ # 年を特定する
46
+ #
47
+ # @param [Array<Year>] years 範囲
48
+ # @param [Western::Calendar] start_date 西暦開始日
49
+ # @param [Western::Calendar] last_date 西暦終了日
50
+ #
51
+ # @return [Array<Month>] 特定月
52
+ #
53
+ def self.specify(years: [], start_date: Western::Calendar.new,
54
+ last_date: Western::Calendar.new)
55
+ result = []
56
+ years.each do |year|
57
+ result |= specify_month(
58
+ year: year, start_date: start_date, last_date: last_date
59
+ )
60
+ end
61
+
62
+ result
63
+ end
64
+ private_class_method :specify
65
+
66
+ # :reek:TooManyStatements { max_statements: 7 }
67
+
68
+ #
69
+ # 月を特定する
70
+ #
71
+ # @param [Year] year 年
72
+ # @param [Western::Calendar] start_date 西暦開始日
73
+ # @param [Western::Calendar] last_date 西暦終了日
74
+ #
75
+ # @return [Month] 対象月
76
+ #
77
+ def self.specify_month(year:, start_date: Western::Calendar.new,
78
+ last_date: Western::Calendar.new)
79
+ months = year.months
80
+
81
+ specify_months = []
82
+ months.each do |month|
83
+ next unless include?(month: month, start_date: start_date, last_date: last_date)
84
+
85
+ monthly_start_date = month.western_date.clone
86
+ monthly_last_date = month.last_date.clone
87
+
88
+ monthly_start_date = start_date.clone if start_date > monthly_start_date
89
+
90
+ monthly_last_date = last_date.clone if last_date < monthly_last_date
91
+
92
+ specify_months.push(
93
+ Month.new(year: year, month: month,
94
+ start_date: monthly_start_date, last_date: monthly_last_date)
95
+ )
96
+ end
97
+
98
+ specify_months
99
+ end
100
+ private_class_method :specify_month
101
+
102
+ #
103
+ # 月が範囲に含まれるか
104
+ #
105
+ # @param [Monthly::Month] month 月
106
+ # @param [Western::Calendar] start_date 西暦開始日
107
+ # @param [Western::Calendar] last_date 西暦終了日
108
+ #
109
+ # @return [True] 含む
110
+ # @return [False] 含まない
111
+ #
112
+ def self.include?(month:, start_date:, last_date:)
113
+ monthly_start_date = month.western_date.clone
114
+ monthly_last_date = month.last_date.clone
115
+
116
+ return false if monthly_start_date.invalid?
117
+
118
+ return false if monthly_last_date.invalid?
119
+
120
+ return false if under(monthly_start_date: monthly_start_date,
121
+ start_date: start_date, last_date: last_date)
122
+
123
+ return false if over(monthly_last_date: monthly_last_date,
124
+ start_date: start_date, last_date: last_date)
125
+
126
+ true
127
+ end
128
+ private_class_method :include?
129
+
130
+ #
131
+ # 範囲が月より前にあるか
132
+ #
133
+ # @param [Western::Calendar] monthly_start_date 月初日
134
+ # @param [Western::Calendar] start_date 西暦開始日
135
+ # @param [Western::Calendar] last_date 西暦終了日
136
+ #
137
+ # @return [True] 前にある
138
+ # @return [False] 前にない
139
+ #
140
+ def self.under(monthly_start_date:, start_date:, last_date:)
141
+ start_date < monthly_start_date && last_date < monthly_start_date
142
+ end
143
+ private_class_method :under
144
+
145
+ #
146
+ # 範囲が月より後にあるか
147
+ #
148
+ # @param [Western::Calendar] monthly_start_date 月末日
149
+ # @param [Western::Calendar] start_date 西暦開始日
150
+ # @param [Western::Calendar] last_date 西暦終了日
151
+ #
152
+ # @return [True] 後にある
153
+ # @return [False] 後にない
154
+ #
155
+ def self.over(monthly_last_date:, start_date:, last_date:)
156
+ start_date > monthly_last_date && last_date > monthly_last_date
157
+ end
158
+ private_class_method :over
159
+ end
160
+ end
161
+ end
162
+ end
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../base/multi_gengou_roller'
4
3
  require_relative '../base/year'
5
4
 
6
- require_relative '../../era/western'
5
+ require_relative '../../era/western/calendar'
7
6
  require_relative '../../output/response'
8
7
  require_relative '../../output/logger'
9
8
 
@@ -29,11 +28,7 @@ module Zakuro
29
28
  # @return [Result::Data::SingleDay] 和暦日
30
29
  #
31
30
  def self.get(years: [], date: Western::Calendar.new)
32
- year = specify_year(years: years, date: date)
33
-
34
- year = transfer(year: year, date: date)
35
-
36
- month = specify_month(year: year, date: date)
31
+ year, month = specify(years: years, date: date)
37
32
  first_date = month.western_date
38
33
 
39
34
  Output::Response::SingleDay.save_single_day(
@@ -50,57 +45,40 @@ module Zakuro
50
45
  # @param [Array<Year>] years 範囲
51
46
  # @param [Western::Calendar] date 西暦日
52
47
  #
53
- # @return [Year] 対象年
48
+ # @return [Base::Year] 対象年
49
+ # @return [Base::Month] 対象月
54
50
  #
55
- def self.specify_year(years:, date:)
56
- years.reverse_each do |year|
57
- return year if date >= year.new_year_date
51
+ def self.specify(years:, date:)
52
+ years.each do |year|
53
+ month = specify_month(year: year, date: date)
54
+ return year, month unless month.invalid?
58
55
  end
59
56
 
60
57
  raise ArgumentError, "invalid year range. date: #{date.format}"
61
58
  end
62
- private_class_method :specify_year
63
-
64
- #
65
- # 改元する
66
- #
67
- # @param [Year] year 年
68
- # @param [Western::Calendar] date 西暦日
69
- #
70
- # @return [Year] 改元後の年
71
- #
72
- def self.transfer(year:, date:)
73
- multi_gengou = Calculation::Base::MultiGengouRoller.transfer(
74
- multi_gengou: year.multi_gengou, date: date
75
- )
76
- Calculation::Base::Year.new(
77
- multi_gengou: multi_gengou, new_year_date: year.new_year_date,
78
- months: year.months, total_days: year.total_days
79
- )
80
- end
81
- private_class_method :transfer
59
+ private_class_method :specify
82
60
 
83
61
  # :reek:TooManyStatements { max_statements: 7 }
84
62
 
85
63
  #
86
64
  # 月を特定する
87
65
  #
88
- # @param [Year] year 年
66
+ # @param [Base::Year] year 年
89
67
  # @param [Western::Calendar] date 西暦日
90
68
  #
91
- # @return [Month] 対象月
69
+ # @return [Base::Month] 対象月
92
70
  #
93
71
  def self.specify_month(year:, date:)
94
72
  months = year.months
95
73
 
96
- current_month = months[0]
97
74
  months.each do |month|
98
- return current_month if month.western_date > date
75
+ western_date = month.western_date
76
+ next if western_date.invalid?
99
77
 
100
- current_month = month
78
+ return month if month.include?(date: date)
101
79
  end
102
80
 
103
- current_month
81
+ Monthly::Month.new
104
82
  end
105
83
  private_class_method :specify_month
106
84
  end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../operation/operation'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Summary
11
+ #
12
+ # Operation 運用情報
13
+ #
14
+ module Operation
15
+ #
16
+ # 運用情報を生成する
17
+ #
18
+ # @param [Result::Data::SingleDay] calc_date 和暦日(計算値)
19
+ #
20
+ # @return [Result::Operation::Bundle] 運用情報
21
+ #
22
+ def self.create(calc_date: Result::Data::SingleDay.new)
23
+ first_day = calc_date.month.first_day.western_date
24
+ operation_history = Zakuro::Operation.specify_history(western_date: first_day)
25
+
26
+ operation_month = create_operation_month(operation_history: operation_history)
27
+
28
+ Result::Operation::Bundle.new(
29
+ operated: !operation_history.invalid?, month: operation_month, original: calc_date
30
+ )
31
+ end
32
+
33
+ #
34
+ # 月履歴集約情報を生成する
35
+ #
36
+ # @param [Operation::MonthHistory] operation_history 変更履歴(月)
37
+ #
38
+ # @return [Result::Operation::Month::Bundle] 月履歴集約情報
39
+ #
40
+ def self.create_operation_month(operation_history: Operation::MonthHistory.new)
41
+ return Result::Operation::Month::Bundle.new if operation_history.invalid?
42
+
43
+ parent_operation_history = Zakuro::Operation.specify_history_by_id(
44
+ id: operation_history.parent_id
45
+ )
46
+
47
+ Result::Operation::Month::Bundle.new(
48
+ current: create_operation_month_history(operation_history: operation_history),
49
+ parent: create_operation_month_history(operation_history: parent_operation_history)
50
+ )
51
+ end
52
+ private_class_method :create_operation_month
53
+
54
+ #
55
+ # 月別履歴情報を生成する
56
+ #
57
+ # @param [Operation::MonthHistory] operation_history 変更履歴(月)
58
+ #
59
+ # @return [Result::Operation::Month::History] 月別履歴情報
60
+ #
61
+ def self.create_operation_month_history(operation_history: Operation::MonthHistory.new)
62
+ return Result::Operation::Month::History.new if operation_history.invalid?
63
+
64
+ annotations = create_annnotations(operation_history: operation_history)
65
+
66
+ reference = operation_history.reference
67
+ Result::Operation::Month::History.new(
68
+ id: operation_history.id, western_date: operation_history.western_date.format,
69
+ page: reference.page, number: reference.number, annotations: annotations
70
+ )
71
+ end
72
+ private_class_method :create_operation_month_history
73
+
74
+ #
75
+ # 注釈情報を生成する
76
+ #
77
+ # @param [Operation::MonthHistory] operation_history 変更履歴(月)
78
+ #
79
+ # @return [Array<Result::Operation::Month::Annotation>] 注釈
80
+ #
81
+ def self.create_annnotations(operation_history: Operation::MonthHistory.new)
82
+ annotations = []
83
+ operation_history.annotations.each do |annotation|
84
+ annotations.push(
85
+ Result::Operation::Month::Annotation.new(
86
+ description: annotation.description,
87
+ note: annotation.note
88
+ )
89
+ )
90
+ end
91
+
92
+ annotations
93
+ end
94
+ private_class_method :create_annnotations
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../specifier/multiple_day'
4
+
5
+ require_relative '../range/operated_range'
6
+
7
+ require_relative '../range/full_range'
8
+
9
+ require_relative './internal/operation'
10
+
11
+ # :nodoc:
12
+ module Zakuro
13
+ # :nodoc:
14
+ module Calculation
15
+ # :nodoc:
16
+ module Summary
17
+ #
18
+ # Range 期間
19
+ #
20
+ module Range
21
+ #
22
+ # 生成する
23
+ #
24
+ # @param [Context] context 暦コンテキスト
25
+ # @param [Western::Calendar] start_date 西暦開始日
26
+ # @param [Western::Calendar] last_date 西暦終了日
27
+ #
28
+ # @return [Result::Range] 期間検索結果(和暦日)
29
+ #
30
+ def self.get(context:, start_date: Western::Calendar.new, last_date: Western::Calendar.new)
31
+ years = get_full_range_years(
32
+ context: context, start_date: start_date, last_date: last_date
33
+ )
34
+ operated_years = get_operated_range_years(
35
+ context: context, years: years, start_date: start_date, last_date: last_date
36
+ )
37
+
38
+ dates = Specifier::MultipleDay.get(
39
+ years: years, start_date: start_date, last_date: last_date
40
+ )
41
+
42
+ operated_dates = Specifier::MultipleDay.get(
43
+ years: operated_years, start_date: start_date, last_date: last_date
44
+ )
45
+
46
+ list = create_result_list(dates: dates, operated_dates: operated_dates)
47
+
48
+ Result::Range.new(list: list)
49
+ end
50
+
51
+ #
52
+ # 完全範囲を取得する
53
+ #
54
+ # @param [Context] context 暦コンテキスト
55
+ # @param [Western::Calendar] start_date 西暦開始日
56
+ # @param [Western::Calendar] last_date 西暦終了日
57
+ #
58
+ # @return [Array<Base::Year>] 完全範囲
59
+ #
60
+ def self.get_full_range_years(context:, start_date: Western::Calendar.new,
61
+ last_date: Western::Calendar.new)
62
+ full_range = Calculation::Range::FullRange.new(
63
+ context: context, start_date: start_date, last_date: last_date
64
+ )
65
+ full_range.get
66
+ end
67
+ private_class_method :get_full_range_years
68
+
69
+ #
70
+ # 運用結果範囲を取得する
71
+ #
72
+ # @param [Context] context 暦コンテキスト
73
+ # @param [Western::Calendar] start_date 西暦開始日
74
+ # @param [Western::Calendar] last_date 西暦終了日
75
+ # @param [Western::Calendar] date 西暦日
76
+ #
77
+ # @return [Array<Base::OperatedYear>] 運用結果範囲
78
+ #
79
+ def self.get_operated_range_years(context:, years:, start_date: Western::Calendar.new,
80
+ last_date: Western::Calendar.new)
81
+ operated_range = Calculation::Range::OperatedRange.new(
82
+ context: context, start_date: start_date, last_date: last_date, years: years
83
+ )
84
+ operated_range.get
85
+ end
86
+ private_class_method :get_operated_range_years
87
+
88
+ #
89
+ # 結果リストを生成する
90
+ #
91
+ # @param [Array<Result::Data::SingleDay>] dates 検索結果(計算値)
92
+ # @param [Array<Result::Data::SingleDay>] operated_dates 検索結果(運用値)
93
+ #
94
+ # @return [Array<Result::Single>] 結果リスト
95
+ #
96
+ def self.create_result_list(dates:, operated_dates:)
97
+ result = []
98
+
99
+ return result if dates.size != operated_dates.size
100
+
101
+ (0..(dates.size - 1)).each do |index|
102
+ data = operated_dates[index]
103
+
104
+ date = dates[index]
105
+ operation = Operation.create(calc_date: date)
106
+
107
+ result.push(
108
+ Result::Single.new(
109
+ data: data,
110
+ operation: operation
111
+ )
112
+ )
113
+ end
114
+
115
+ result
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -6,6 +6,8 @@ require_relative '../range/operated_range'
6
6
 
7
7
  require_relative '../range/full_range'
8
8
 
9
+ require_relative './internal/operation'
10
+
9
11
  # :nodoc:
10
12
  module Zakuro
11
13
  # :nodoc:
@@ -25,104 +27,83 @@ module Zakuro
25
27
  # @return [Result::Single] 一日検索結果(和暦日)
26
28
  #
27
29
  def self.get(context:, date: Western::Calendar.new)
28
- full_range = Calculation::Range::FullRange.new(context: context, start_date: date)
29
- years = full_range.get
30
+ years = get_full_range_years(context: context, date: date)
30
31
 
31
- calc_date = Calculation::Specifier::SingleDay.get(
32
- years: years, date: date
33
- )
32
+ data = get_data(context: context, years: years, date: date)
34
33
 
35
- operated_range = Calculation::Range::OperatedRange.new(context: context, years: years)
34
+ operation = get_operation(years: years, date: date)
36
35
 
37
36
  Result::Single.new(
38
- data: Calculation::Specifier::SingleDay.get(
39
- years: operated_range.get, date: date
40
- ),
41
- operation: create_operation(calc_date: calc_date)
37
+ data: data,
38
+ operation: operation
42
39
  )
43
40
  end
44
41
 
45
42
  #
46
- # 運用情報を生成する
43
+ # 完全範囲を取得する
47
44
  #
48
- # @param [Result::Data::SingleDay] calc_date 和暦日(計算値)
45
+ # @param [Context] context 暦コンテキスト
46
+ # @param [Western::Calendar] date 西暦日
49
47
  #
50
- # @return [Result::Operation::Bundle] 運用情報
48
+ # @return [Array<Base::Year>] 完全範囲
51
49
  #
52
- def self.create_operation(calc_date: Result::Data::SingleDay.new)
53
- first_day = calc_date.month.first_day.western_date
54
- operation_history = Operation.specify_history(western_date: first_day)
55
-
56
- operation_month = create_operation_month(operation_history: operation_history)
57
-
58
- Result::Operation::Bundle.new(
59
- operated: !operation_history.invalid?, month: operation_month, original: calc_date
60
- )
50
+ def self.get_full_range_years(context:, date: Western::Calendar.new)
51
+ full_range = Calculation::Range::FullRange.new(context: context, start_date: date)
52
+ full_range.get
61
53
  end
62
- private_class_method :create_operation
54
+ private_class_method :get_full_range_years
63
55
 
64
56
  #
65
- # 月履歴集約情報を生成する
57
+ # 運用結果範囲を取得する
66
58
  #
67
- # @param [Operation::MonthHistory] operation_history 変更履歴(月)
59
+ # @param [Context] context 暦コンテキスト
60
+ # @param [Array<Base::Year>] years 完全範囲
61
+ # @param [Western::Calendar] date 西暦日
68
62
  #
69
- # @return [Result::Operation::Month::Bundle] 月履歴集約情報
63
+ # @return [Array<Base::OperatedYear>] 運用結果範囲
70
64
  #
71
- def self.create_operation_month(operation_history: Operation::MonthHistory.new)
72
- return Result::Operation::Month::Bundle.new if operation_history.invalid?
73
-
74
- parent_operation_history = Operation.specify_history_by_id(
75
- id: operation_history.parent_id
76
- )
77
-
78
- Result::Operation::Month::Bundle.new(
79
- current: create_operation_month_history(operation_history: operation_history),
80
- parent: create_operation_month_history(operation_history: parent_operation_history)
65
+ def self.get_operated_range_years(context:, years:, date: Western::Calendar.new)
66
+ operated_range = Calculation::Range::OperatedRange.new(
67
+ context: context, start_date: date, years: years
81
68
  )
69
+ operated_range.get
82
70
  end
83
- private_class_method :create_operation_month
71
+ private_class_method :get_operated_range_years
84
72
 
85
73
  #
86
- # 月別履歴情報を生成する
74
+ # 1日を取得する
87
75
  #
88
- # @param [Operation::MonthHistory] operation_history 変更履歴(月)
76
+ # @param [Context] context 暦コンテキスト
77
+ # @param [Array<Base::Year>] years 完全範囲
78
+ # @param [Western::Calendar] date 西暦日
89
79
  #
90
- # @return [Result::Operation::Month::History] 月別履歴情報
80
+ # @return [Data::SingleDay] 1日
91
81
  #
92
- def self.create_operation_month_history(operation_history: Operation::MonthHistory.new)
93
- return Result::Operation::Month::History.new if operation_history.invalid?
82
+ def self.get_data(context:, years:, date: Western::Calendar.new)
83
+ operated_years = get_operated_range_years(context: context, years: years, date: date)
94
84
 
95
- annotations = create_annnotations(operation_history: operation_history)
96
-
97
- reference = operation_history.reference
98
- Result::Operation::Month::History.new(
99
- id: operation_history.id, western_date: operation_history.western_date.format,
100
- page: reference.page, number: reference.number, annotations: annotations
85
+ Calculation::Specifier::SingleDay.get(
86
+ years: operated_years, date: date
101
87
  )
102
88
  end
103
- private_class_method :create_operation_month_history
89
+ private_class_method :get_data
104
90
 
105
91
  #
106
- # 注釈情報を生成する
92
+ # 完全範囲を取得する
107
93
  #
108
- # @param [Operation::MonthHistory] operation_history 変更履歴(月)
94
+ # @param [Context] context 暦コンテキスト
95
+ # @param [Western::Calendar] date 西暦日
109
96
  #
110
- # @return [Array<Result::Operation::Month::Annotation>] 注釈
97
+ # @return [Array<Base::Year>] 完全範囲
111
98
  #
112
- def self.create_annnotations(operation_history: Operation::MonthHistory.new)
113
- annotations = []
114
- operation_history.annotations.each do |annotation|
115
- annotations.push(
116
- Result::Operation::Month::Annotation.new(
117
- description: annotation.description,
118
- note: annotation.note
119
- )
120
- )
121
- end
99
+ def self.get_operation(years:, date: Western::Calendar.new)
100
+ calc_date = Calculation::Specifier::SingleDay.get(
101
+ years: years, date: date
102
+ )
122
103
 
123
- annotations
104
+ Operation.create(calc_date: calc_date)
124
105
  end
125
- private_class_method :create_annnotations
106
+ private_class_method :get_operation
126
107
  end
127
108
  end
128
109
  end
@@ -87,6 +87,20 @@ module Zakuro
87
87
 
88
88
  failed
89
89
  end
90
+
91
+ #
92
+ # 不正か
93
+ #
94
+ # @return [True] 不正
95
+ # @return [False] 不正なし
96
+ #
97
+ def invalid?
98
+ return true unless @start
99
+
100
+ return true unless @end
101
+
102
+ false
103
+ end
90
104
  end
91
105
 
92
106
  #