zakuro 0.0.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +102 -42
  3. data/doc/operation.md +25 -0
  4. data/doc/operation/csv/month.csv +202 -0
  5. data/doc/operation/operation.xlsx +0 -0
  6. data/doc/operation/transfer.rb +77 -0
  7. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  8. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  9. data/lib/zakuro/calculation/base/year.rb +107 -0
  10. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +459 -0
  11. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
  12. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  13. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  14. data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
  15. data/lib/zakuro/calculation/monthly/month.rb +187 -0
  16. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  17. data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
  18. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  19. data/lib/zakuro/calculation/range/operated_range.rb +144 -0
  20. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  21. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
  22. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
  23. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  24. data/lib/zakuro/calculation/summary/single.rb +129 -0
  25. data/lib/zakuro/condition.rb +16 -13
  26. data/lib/zakuro/era/japan/gengou.rb +106 -0
  27. data/lib/zakuro/era/japan/gengou/parser.rb +167 -0
  28. data/lib/zakuro/era/japan/gengou/type.rb +178 -0
  29. data/lib/zakuro/era/japan/gengou/validator.rb +236 -0
  30. data/lib/zakuro/era/japan/reki.rb +91 -0
  31. data/lib/zakuro/era/{gengou → japan/yaml}/set-001-until-south.yaml +0 -0
  32. data/lib/zakuro/era/{gengou → japan/yaml}/set-002-from-north.yaml +0 -0
  33. data/lib/zakuro/era/{gengou → japan/yaml}/set-003-modern.yaml +0 -0
  34. data/lib/zakuro/era/western.rb +1 -1
  35. data/lib/zakuro/merchant.rb +2 -2
  36. data/lib/zakuro/operation/month/parser.rb +373 -0
  37. data/lib/zakuro/operation/month/type.rb +453 -0
  38. data/lib/zakuro/operation/month/validator.rb +802 -0
  39. data/lib/zakuro/operation/operation.rb +66 -0
  40. data/lib/zakuro/operation/yaml/month.yaml +6452 -0
  41. data/lib/zakuro/output/error.rb +7 -4
  42. data/lib/zakuro/output/logger.rb +50 -47
  43. data/lib/zakuro/output/response.rb +146 -143
  44. data/lib/zakuro/result/core.rb +52 -0
  45. data/lib/zakuro/result/data.rb +187 -0
  46. data/lib/zakuro/result/operation.rb +114 -0
  47. data/lib/zakuro/result/result.rb +37 -0
  48. data/lib/zakuro/{output → tools}/stringifier.rb +16 -9
  49. data/lib/zakuro/tools/typeof.rb +33 -0
  50. data/lib/zakuro/version.rb +1 -1
  51. data/lib/zakuro/version/abstract_version.rb +1 -1
  52. data/lib/zakuro/version/context.rb +23 -0
  53. data/lib/zakuro/version/senmyou/cycle/remainder.rb +63 -0
  54. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +31 -0
  55. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +186 -182
  56. data/lib/zakuro/version/senmyou/range/annual_range.rb +167 -0
  57. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  58. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +6 -6
  59. data/lib/zakuro/version/senmyou/stella/solar_average.rb +103 -152
  60. data/lib/zakuro/version/senmyou/stella/solar_location.rb +213 -0
  61. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +3 -184
  62. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +4 -4
  63. data/lib/zakuro/version/version_class_resolver.rb +62 -0
  64. data/lib/zakuro/version_factory.rb +3 -3
  65. metadata +53 -24
  66. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  67. data/lib/zakuro/cycle/zodiac.rb +0 -103
  68. data/lib/zakuro/era/japan.rb +0 -664
  69. data/lib/zakuro/output/result.rb +0 -225
  70. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  71. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  72. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -205
  73. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  74. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -66
  75. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  76. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -122
  77. data/lib/zakuro/version/senmyou/summary/annual_range.rb +0 -187
  78. data/lib/zakuro/version/senmyou/summary/full_range.rb +0 -224
  79. data/lib/zakuro/version/senmyou/summary/specifier.rb +0 -100
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Range
9
+ # :nodoc:
10
+ module Transfer
11
+ #
12
+ # WesternDateAllocation 西暦日の割り当て
13
+ #
14
+ module WesternDateAllocation
15
+ #
16
+ # 月初日の西暦日を更新する
17
+ #
18
+ # @param [Context] context 暦コンテキスト
19
+ # @param [Array<Year>] years 完全範囲(月初日なし)
20
+ #
21
+ # @return [Array<Year>] 完全範囲(月初日あり)
22
+ #
23
+ def self.get(context:, years:)
24
+ update_first_day(context: context, years: years)
25
+
26
+ years
27
+ end
28
+
29
+ #
30
+ # 月初日の西暦日を更新する
31
+ #
32
+ # @param [Context] context 暦コンテキスト
33
+ # @param [Array<Year>] years 完全範囲(月初日なし)
34
+ #
35
+ def self.update_first_day(context:, years:)
36
+ years.each_with_index do |year, index|
37
+ new_year_date = year.new_year_date.clone
38
+
39
+ months = year.months
40
+ update_first_day_within_all_months(
41
+ context: context,
42
+ new_year_date: new_year_date, months: months
43
+ )
44
+
45
+ years[index] = Base::Year.new(
46
+ multi_gengou: year.multi_gengou, new_year_date: new_year_date,
47
+ months: months, total_days: year.total_days
48
+ )
49
+ end
50
+ end
51
+
52
+ #
53
+ # 全ての月で月初日の西暦日を更新する
54
+ #
55
+ # @param [Context] context 暦コンテキスト
56
+ # @param [Western::Calendar] new_year_date 元旦
57
+ # @param [Array<Month>] months 月データ
58
+ #
59
+ def self.update_first_day_within_all_months(context:,
60
+ new_year_date:, months:)
61
+ date = new_year_date.clone
62
+ months.each_with_index do |month, index|
63
+ updated_month = Monthly::Month.new(
64
+ context: context,
65
+ month_label: month.month_label,
66
+ first_day: Monthly::FirstDay.new(
67
+ remainder: month.first_day.remainder,
68
+ western_date: date
69
+ ),
70
+ solar_terms: month.solar_terms
71
+ )
72
+ months[index] = updated_month
73
+
74
+ date = date.clone + updated_month.days
75
+ end
76
+ end
77
+ private_class_method :update_first_day_within_all_months
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../calculation/base/multi_gengou_roller'
4
+ require_relative '../../../calculation/base/year'
5
+
6
+ require_relative '../../../era/western'
7
+
8
+ # :nodoc:
9
+ module Zakuro
10
+ # :nodoc:
11
+ module Calculation
12
+ # :nodoc:
13
+ module Range
14
+ # :nodoc:
15
+ module Transfer
16
+ #
17
+ # YearBoundary 年境界
18
+ #
19
+ module YearBoundary
20
+ #
21
+ # 年間範囲内の年データの開始月を変更する
22
+ #
23
+ # @param [Context] context 暦コンテキスト
24
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
25
+ #
26
+ # @return [Array<Year>] 年データ(元旦基準)
27
+ #
28
+ def self.get(context:, annual_ranges:)
29
+ categorize(context: context, annual_ranges: annual_ranges)
30
+ rearranged_years(annual_ranges: annual_ranges)
31
+ end
32
+
33
+ #
34
+ # 年間範囲内の年データの開始月を変更する
35
+ #
36
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
37
+ #
38
+ # @return [Array<Year>] 年データ(元旦基準)
39
+ #
40
+ def self.rearranged_years(annual_ranges:)
41
+ years = []
42
+
43
+ (0..(annual_ranges.size - 2)).each do |index|
44
+ year = rearranged_year(annual_ranges: annual_ranges, index: index)
45
+ years.push(year)
46
+ end
47
+
48
+ years
49
+ end
50
+ private_class_method :rearranged_years
51
+
52
+ #
53
+ # 年間範囲を昨年/今年で分類する
54
+ #
55
+ # @param [Context] context 暦コンテキスト
56
+ # @param [Array<Year>] annual_range 1年データ
57
+ #
58
+ def self.categorize(context:, annual_ranges:)
59
+ annual_ranges.each do |annual_range|
60
+ categorize_year(context: context, annual_range: annual_range)
61
+ end
62
+ end
63
+ private_class_method :categorize
64
+
65
+ #
66
+ # 各月を昨年/今年で分類する
67
+ #
68
+ # @param [Context] context 暦コンテキスト
69
+ # @param [Array<Month>] annual_range 1年データ
70
+ #
71
+ def self.categorize_year(context:, annual_range:)
72
+ is_last_year = true
73
+ annual_range.each_with_index do |month, index|
74
+ is_last_year = false if month.number == 1
75
+
76
+ annual_range[index] = Monthly::InitializedMonth.new(
77
+ context: context,
78
+ month_label: month.month_label, first_day: month.first_day,
79
+ solar_terms: month.solar_terms, phase_index: month.phase_index,
80
+ is_last_year: is_last_year
81
+ )
82
+ end
83
+ end
84
+ private_class_method :categorize_year
85
+
86
+ #
87
+ # 年データの開始月を変更する
88
+ #
89
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
90
+ # @param [Integer] index 対象年の要素番号
91
+ #
92
+ # @return [Year] 年データ(元旦基準)
93
+ #
94
+ def self.rearranged_year(annual_ranges:, index:)
95
+ current_annual_range = annual_ranges[index]
96
+ next_annual_range = annual_ranges[index + 1]
97
+
98
+ year = push_current_year(annual_range: current_annual_range)
99
+ push_last_year(annual_range: next_annual_range, year: year)
100
+
101
+ year
102
+ end
103
+ private_class_method :rearranged_year
104
+
105
+ #
106
+ # 当年データを生成する
107
+ #
108
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
109
+ # @param [Year] year 対象年
110
+ #
111
+ # @return [Year] 当年月ありの対象年
112
+ #
113
+ def self.push_current_year(annual_range:, year: Base::Year.new)
114
+ annual_range.each do |month|
115
+ next if month.is_last_year
116
+
117
+ year.push(month: month)
118
+ end
119
+
120
+ year
121
+ end
122
+ private_class_method :push_current_year
123
+
124
+ #
125
+ # 昨年データを生成する
126
+ #
127
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
128
+ # @param [Year] year 対象年
129
+ #
130
+ # @return [Year] 昨年月ありの対象年
131
+ #
132
+ def self.push_last_year(annual_range:, year: Base::Year.new)
133
+ annual_range.each do |month|
134
+ next unless month.is_last_year
135
+
136
+ year.push(month: month)
137
+ end
138
+
139
+ year
140
+ end
141
+ private_class_method :push_last_year
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../base/multi_gengou_roller'
4
+ require_relative '../base/year'
5
+
6
+ require_relative '../../era/western'
7
+ require_relative '../../output/response'
8
+ require_relative '../../output/logger'
9
+
10
+ # :nodoc:
11
+ module Zakuro
12
+ # :nodoc:
13
+ module Calculation
14
+ # :nodoc:
15
+ module Specifier
16
+ #
17
+ # SingleDay 一日検索
18
+ #
19
+ module SingleDay
20
+ # @return [Output::Logger] ロガー
21
+ LOGGER = Output::Logger.new(location: 'specifier')
22
+
23
+ #
24
+ # 取得する
25
+ #
26
+ # @param [Array<Year>] yeas 範囲
27
+ # @param [Western::Calendar] date 西暦日
28
+ #
29
+ # @return [Result::Data::SingleDay] 和暦日
30
+ #
31
+ 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)
37
+ first_date = month.western_date
38
+
39
+ Output::Response::SingleDay.save_single_day(
40
+ param: Output::Response::SingleDay::Param.new(
41
+ year: year, month: month,
42
+ date: date, days: date - first_date
43
+ )
44
+ )
45
+ end
46
+
47
+ #
48
+ # 年を特定する
49
+ #
50
+ # @param [Array<Year>] years 範囲
51
+ # @param [Western::Calendar] date 西暦日
52
+ #
53
+ # @return [Year] 対象年
54
+ #
55
+ def self.specify_year(years:, date:)
56
+ years.reverse_each do |year|
57
+ return year if date >= year.new_year_date
58
+ end
59
+
60
+ raise ArgumentError, "invalid year range. date: #{date.format}"
61
+ 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
82
+
83
+ # :reek:TooManyStatements { max_statements: 7 }
84
+
85
+ #
86
+ # 月を特定する
87
+ #
88
+ # @param [Year] year 年
89
+ # @param [Western::Calendar] date 西暦日
90
+ #
91
+ # @return [Month] 対象月
92
+ #
93
+ def self.specify_month(year:, date:)
94
+ months = year.months
95
+
96
+ current_month = months[0]
97
+ months.each do |month|
98
+ return current_month if month.western_date > date
99
+
100
+ current_month = month
101
+ end
102
+
103
+ current_month
104
+ end
105
+ private_class_method :specify_month
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../specifier/single_day'
4
+
5
+ require_relative '../range/operated_range'
6
+
7
+ require_relative '../range/full_range'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Calculation
13
+ # :nodoc:
14
+ module Summary
15
+ #
16
+ # Single 一日
17
+ #
18
+ module Single
19
+ #
20
+ # 生成する
21
+ #
22
+ # @param [Context] context 暦コンテキスト
23
+ # @param [Western::Calendar] date 西暦日
24
+ #
25
+ # @return [Result::Single] 一日検索結果(和暦日)
26
+ #
27
+ 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
+
31
+ calc_date = Calculation::Specifier::SingleDay.get(
32
+ years: years, date: date
33
+ )
34
+
35
+ operated_range = Calculation::Range::OperatedRange.new(context: context, years: years)
36
+
37
+ 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)
42
+ )
43
+ end
44
+
45
+ #
46
+ # 運用情報を生成する
47
+ #
48
+ # @param [Result::Data::SingleDay] calc_date 和暦日(計算値)
49
+ #
50
+ # @return [Result::Operation::Bundle] 運用情報
51
+ #
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
+ )
61
+ end
62
+ private_class_method :create_operation
63
+
64
+ #
65
+ # 月履歴集約情報を生成する
66
+ #
67
+ # @param [Operation::MonthHistory] operation_history 変更履歴(月)
68
+ #
69
+ # @return [Result::Operation::Month::Bundle] 月履歴集約情報
70
+ #
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)
81
+ )
82
+ end
83
+ private_class_method :create_operation_month
84
+
85
+ #
86
+ # 月別履歴情報を生成する
87
+ #
88
+ # @param [Operation::MonthHistory] operation_history 変更履歴(月)
89
+ #
90
+ # @return [Result::Operation::Month::History] 月別履歴情報
91
+ #
92
+ def self.create_operation_month_history(operation_history: Operation::MonthHistory.new)
93
+ return Result::Operation::Month::History.new if operation_history.invalid?
94
+
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
101
+ )
102
+ end
103
+ private_class_method :create_operation_month_history
104
+
105
+ #
106
+ # 注釈情報を生成する
107
+ #
108
+ # @param [Operation::MonthHistory] operation_history 変更履歴(月)
109
+ #
110
+ # @return [Array<Result::Operation::Month::Annotation>] 注釈
111
+ #
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
122
+
123
+ annotations
124
+ end
125
+ private_class_method :create_annnotations
126
+ end
127
+ end
128
+ end
129
+ end