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
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../../cycle/abstract_remainder'
4
-
5
- # :nodoc:
6
- module Zakuro
7
- # :nodoc:
8
- module Senmyou
9
- #
10
- # Remainder 宣明暦の時刻情報(大余小余)
11
- #
12
- # * 「15日1835分5秒」のような形式で表される
13
- # * 分は8400で一日に繰り上げる
14
- # * 秒は基本的に1/8分で、8秒で1分に繰り上げる。ただし、月補正値は1分に100秒とするなど基数の変更がありえる
15
- # * 十干十二支(60日)を上限とした「日時分秒」の情報で、日付(date)/時刻(time)と部分的に重なる概念
16
- #
17
- class Remainder < Cycle::AbstractRemainder
18
- # @return [Integer] 統法(1日=8400分)
19
- DAY = 8400
20
- # @return [Integer] 分(1分=8秒)
21
- MINUTE = 8
22
-
23
- #
24
- # 初期化
25
- #
26
- # @param [Integer] day 大余("日"に相当)
27
- # @param [Integer] minute 小余("分"に相当)
28
- # @param [Integer] second 秒
29
- # @param [Integer] total 繰り上げなしの小余
30
- #
31
- def initialize(day: -1, minute: -1, second: -1, total: -1)
32
- super(base_day: DAY, base_mitune: MINUTE,
33
- day: day, minute: minute, second: second, total: total)
34
- end
35
- end
36
-
37
- #
38
- # LunarRemainder 月の位相計算向け時刻情報(大余小余)
39
- #
40
- class LunarRemainder < Cycle::AbstractRemainder
41
- # @return [Integer] 統法(1日=8400分)
42
- DAY = 8400
43
- # @return [Integer] 分(1分=100秒)
44
- MINUTE = 100
45
-
46
- #
47
- # 初期化
48
- #
49
- # @param [Integer] day 大余("日"に相当)
50
- # @param [Integer] minute 小余("分"に相当)
51
- # @param [Integer] second 秒
52
- # @param [Integer] total 繰り上げなしの小余
53
- #
54
- def initialize(day: -1, minute: -1, second: -1, total: -1)
55
- super(base_day: DAY, base_mitune: MINUTE,
56
- day: day, minute: minute, second: second, total: total)
57
- end
58
- end
59
- end
60
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nodoc:
4
- module Zakuro
5
- # :nodoc:
6
- module Senmyou
7
- #
8
- # SolarTerm 二十四節気
9
- #
10
- class SolarTerm
11
- # @return [Integer] 連番
12
- attr_reader :index
13
- # @return [Remainder] 時刻情報(大余小余)
14
- attr_reader :remainder
15
-
16
- # @return [Hash<Integer, Symbol>] 順序
17
- ORDER = {
18
- 0 => :touji,
19
- 1 => :shoukan,
20
- 2 => :daikan,
21
- 3 => :risshun,
22
- 4 => :usui,
23
- 5 => :keichitsu,
24
- 6 => :shunbun,
25
- 7 => :seimei,
26
- 8 => :kokuu,
27
- 9 => :rikka,
28
- 10 => :shouman,
29
- 11 => :boushu,
30
- 12 => :geshi,
31
- 13 => :shousho,
32
- 14 => :taisho,
33
- 15 => :risshuu,
34
- 16 => :shosho,
35
- 17 => :hakuro,
36
- 18 => :shuubun,
37
- 19 => :kanro,
38
- 20 => :soukou,
39
- 21 => :rittou,
40
- 22 => :shousetsu,
41
- 23 => :taisetsu
42
- }.freeze
43
-
44
- #
45
- # 初期化
46
- #
47
- # @param [Integer] index 連番
48
- # @param [Remainder] remainder 時刻情報(大余小余)
49
- #
50
- def initialize(index: -1, remainder: Remainder.new)
51
- @index = index
52
- @remainder = remainder
53
- end
54
-
55
- #
56
- # 不正かどうか検証する
57
- #
58
- # @return [True] 正しくない
59
- # @return [False] 正しい
60
- #
61
- def invalid?
62
- (@index == -1 || @remainder.invalid?)
63
- end
64
- end
65
- end
66
- end
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './era'
4
-
5
- # :nodoc:
6
- module Zakuro
7
- # :nodoc:
8
- module Senmyou
9
- #
10
- # Year 年
11
- #
12
- class Year
13
- # @return [Gengou] 元号
14
- attr_reader :multi_gengou
15
- # @return [Array<Month>] 年内の全ての月
16
- attr_reader :months
17
- # @return [Integer] 年の日数
18
- attr_reader :total_days
19
- # @return [Western::Calendar] 元旦
20
- attr_reader :new_year_date
21
-
22
- #
23
- # 初期化
24
- #
25
- # @param [Gengou] multi_gengou 元号
26
- #
27
- def initialize(multi_gengou: MultiGengou.new, new_year_date: Western::Calendar.new,
28
- months: [], total_days: 0)
29
- @multi_gengou = multi_gengou
30
- @months = months
31
- @new_year_date = new_year_date
32
- @total_days = total_days
33
- end
34
-
35
- #
36
- # 年の日数を確定する
37
- #
38
- def commit
39
- @total_days = 0
40
- months.each do |month|
41
- @total_days += month.days
42
- end
43
-
44
- self
45
- end
46
-
47
- #
48
- # 次年にする
49
- #
50
- # @param [Japan::Gengou] first_line 元号(1行目)
51
- # @param [Japan::Gengou] second_line 元号(2行目)
52
- #
53
- # @return [MultiGengou] 自身
54
- #
55
- def next_year
56
- @multi_gengou.next_year
57
-
58
- @new_year_date += @total_days
59
- @total_days = 0
60
-
61
- self
62
- end
63
-
64
- #
65
- # 十干十二支を取得する
66
- #
67
- # @return [String] 十干十二支
68
- #
69
- def zodiac_name
70
- Era.zodiac_name(western_year: @new_year_date.year)
71
- end
72
-
73
- #
74
- # 月を追加する
75
- #
76
- # @param [Month] month 月
77
- #
78
- def push(month:)
79
- return if duplicated?(month: month)
80
-
81
- @months.push(month)
82
-
83
- nil
84
- end
85
-
86
- #
87
- # すでに登録済みの月と重複しているか判定する
88
- #
89
- # @note 昨年11月1日から今年1月1日の前日までで、去年データと重複する場合は登録スキップする
90
- #
91
- # @param [Month] month 月
92
- #
93
- # @return [True] 重複している
94
- # @return [True] 重複していない
95
- #
96
- def duplicated?(month:)
97
- @months.each do |existed|
98
- return true if existed.same?(other: month)
99
- end
100
- false
101
- end
102
- end
103
- end
104
- end
@@ -1,122 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nodoc:
4
- module Zakuro
5
- # :nodoc:
6
- module Senmyou
7
- #
8
- # Month 月情報
9
- #
10
- class Month
11
- # @return [True] 昨年の月
12
- # @return [False] 今年の月
13
- # @note 冬至基準で1年データを作成するため昨年の11月-12月である可能性がある
14
- attr_accessor :is_last_year
15
- # @return [True] 大の月(30日)
16
- # @return [False] 小の月(29日)
17
- attr_accessor :is_many_days
18
- # @return [Integer] 月(xx月のxx)
19
- attr_accessor :number
20
- # @return [True] 閏月
21
- # @return [False] 平月
22
- attr_accessor :leaped
23
- # @return [SolarTerm] 二十四節気(中気)
24
- attr_accessor :even_term
25
- # @return [SolarTerm] 二十四節気(節気)
26
- attr_accessor :odd_term
27
- # @return [Remainder] 月初日の大余小余
28
- attr_reader :remainder
29
- # @return [String] 月齢(朔月、上弦、望月、下弦)
30
- attr_reader :phase_index
31
-
32
- # rubocop:disable Metrics/ParameterLists
33
- # :reek:BooleanParametere
34
-
35
- #
36
- # 初期化
37
- #
38
- # @param [True, False] is_last_year 昨年の月/今年の月
39
- # @param [Integer] number 月(xx月のxx)
40
- # @param [True, False] is_many_days 大の月(30日)/小の月(29日)
41
- # @param [True, False] leaped 閏月/平月
42
- # @param [Remainder] remainder 月初日の大余小余
43
- # @param [String] phase_index 月齢(朔月、上弦、望月、下弦)
44
- # @param [SolarTerm] even_term 二十四節気(中気)
45
- # @param [SolarTerm] odd_term 二十四節気(節気)
46
- #
47
- def initialize(is_last_year: -1, number: -1, is_many_days: false,
48
- leaped: false, remainder: Remainder.new, phase_index: -1,
49
- even_term: SolarTerm.new, odd_term: SolarTerm.new)
50
- # 年
51
- @is_last_year = is_last_year
52
- # 月の大小
53
- @is_many_days = is_many_days
54
- # 月
55
- @number = number
56
- # 閏
57
- @leaped = leaped
58
- # 日
59
- @remainder = remainder
60
- # 月齢(朔月、上弦、望月、下弦)
61
- @phase_index = phase_index
62
- # 中気(二十四節気)
63
- @even_term = even_term
64
- # 節気(二十四節気)
65
- @odd_term = odd_term
66
- end
67
- # rubocop:enable Metrics/ParameterLists
68
-
69
- #
70
- # 月の日数を返す
71
- #
72
- # @return [Integer] 日数
73
- #
74
- def days
75
- @is_many_days ? 30 : 29
76
- end
77
-
78
- #
79
- # 月の名前(大小)を返す
80
- #
81
- # @return [String] 月の名前(大小)
82
- #
83
- def days_name
84
- @is_many_days ? '大' : '小'
85
- end
86
-
87
- #
88
- # 同一の月情報かを検証する
89
- #
90
- # @param [Month] other 他の月情報
91
- #
92
- # @return [True] 同一の月
93
- # @return [False] 異なる月
94
- #
95
- def same?(other:)
96
- @number == other.number && @leaped == other.leaped
97
- end
98
-
99
- #
100
- # 二十四節気が未設定かどうかを検証する
101
- #
102
- # @return [True] 設定なし
103
- # @return [False] 設定あり
104
- #
105
- def empty_solar_term?
106
- @even_term.invalid? && @odd_term.invalid?
107
- end
108
-
109
- #
110
- # 文字化する
111
- #
112
- # @return [String] 文字
113
- #
114
- def to_s
115
- "is_last_year: #{@is_last_year}, number: #{@number}, leaped: #{@leaped}, " \
116
- "remainder: #{@remainder.format}, phase_index: #{@phase_index}, " \
117
- "even_term: #{@even_term.remainder.format}: #{@even_term.index}, " \
118
- "odd_term: #{@odd_term.remainder.format}: #{@odd_term.index}"
119
- end
120
- end
121
- end
122
- end
@@ -1,187 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../../output/logger'
4
- require_relative '../base/remainder'
5
- require_relative '../monthly/month'
6
- require_relative '../base/solar_term'
7
- require_relative '../monthly/lunar_phase'
8
- require_relative '../stella/solar_orbit'
9
- require_relative '../stella/solar_average'
10
- require_relative '../stella/lunar_orbit'
11
-
12
- # :nodoc:
13
- module Zakuro
14
- # :nodoc:
15
- module Senmyou
16
- # AnnualRange 年間データ
17
- module AnnualRange
18
- # @return [Logger] ロガー
19
- LOGGER = Logger.new(location: 'annual_range')
20
-
21
- # :reek:TooManyStatements { max_statements: 6 }
22
-
23
- #
24
- # 11月定朔(冬至が含まれる月の1日:補正済)を求める
25
- #
26
- # @param [Integer] western_year 西暦年
27
- #
28
- # @return [Remainder] 11月定朔
29
- #
30
- def self.calc_last_november_1st(western_year:)
31
- # 天正閏余
32
- winter_solstice_age = \
33
- WinterSolstice.calc_moon_age(western_year: western_year)
34
- # 11月経朔
35
- november_1st = \
36
- WinterSolstice.calc_averaged_last_november_1st(western_year: western_year)
37
- # 11月定朔
38
-
39
- # 補正
40
- correction_value = correction_value_on_last_november_1st(
41
- winter_solstice_age: winter_solstice_age,
42
- western_year: western_year
43
- )
44
-
45
- result = november_1st.add(Remainder.new(day: 0, minute: correction_value,
46
- second: 0))
47
- # 進朔
48
- result.up_on_new_moon!
49
- result
50
- end
51
-
52
- # :reek:TooManyStatements { max_statements: 6 }
53
-
54
- #
55
- # 一覧取得する
56
- #
57
- # * 対象年に対して、前年11月-当年11月までを出力する
58
- # * 対象年(西暦)と計算年(元号x年)の紐付けは行わない
59
- #
60
- # @param [Integer] western_year 西暦年
61
- #
62
- # @return [Array<Month>] 1年データ
63
- #
64
- def self.collect_annual_range_after_last_november_1st(western_year:)
65
- annual_range = initialized_annual_range(western_year: western_year)
66
-
67
- apply_big_and_small_of_the_month(annual_range: annual_range)
68
-
69
- SolarAverage.set_solar_terms_into_annual_range(western_year: western_year,
70
- annual_range: annual_range)
71
-
72
- # 月間隔を取得するためだけの末尾要素を削除
73
- annual_range.pop
74
-
75
- adjust_leap_month(annual_range: annual_range)
76
-
77
- annual_range
78
- end
79
-
80
- #
81
- # 11月定朔の補正値を求める
82
- #
83
- # @param [Remainder] winter_solstice_age 天正閏余
84
- # @param [Integer] western_year 西暦年
85
- #
86
- # @return [Integer] 補正値
87
- #
88
- def self.correction_value_on_last_november_1st(winter_solstice_age:, western_year:)
89
- # 補正
90
- solar_term = SolarTerm.new(
91
- remainder: winter_solstice_age
92
- )
93
- solar_term = \
94
- SolarOrbit.calc_solar_term_by_remainder(
95
- solar_term: solar_term
96
- )
97
-
98
- moon_remainder, is_forward = LunarOrbit.calc_moon_point(
99
- remainder: winter_solstice_age, western_year: western_year
100
- )
101
-
102
- SolarOrbit.calc_sun_orbit_value(solar_term: solar_term) +
103
- LunarOrbit.calc_moon_orbit_value(remainder_month: moon_remainder,
104
- is_forward: is_forward)
105
- end
106
- private_class_method :correction_value_on_last_november_1st
107
-
108
- #
109
- # 1年データを取得する
110
- #
111
- # @param [Integer] western_year 西暦年
112
- #
113
- # @return [Array<Month>] 1年データ
114
- #
115
- def self.initialized_annual_range(western_year:)
116
- result = []
117
- lunar_phase = LunarPhase.new(western_year: western_year)
118
-
119
- is_last_year = true
120
-
121
- monthes = [11, 12] + [*1..12]
122
-
123
- monthes.each do |month|
124
- LOGGER.debug('---', "month: #{month}", "is_last_year: #{is_last_year}")
125
-
126
- adjusted = lunar_phase.next_month
127
-
128
- result.push(
129
- Month.new(is_last_year: is_last_year, number: month,
130
- remainder: adjusted, phase_index: 0)
131
- )
132
- is_last_year = false if month == 12
133
- end
134
- result
135
- end
136
- private_class_method :initialized_annual_range
137
-
138
- #
139
- # 1年データの各月に月の大小を設定する
140
- #
141
- # @param [Array<Month>] annual_range 1年データ
142
- #
143
- def self.apply_big_and_small_of_the_month(annual_range:)
144
- size = annual_range.size - 1
145
- (0...size).each do |idx|
146
- current_month = annual_range[idx]
147
- next_month = annual_range[idx + 1]
148
- current_month.is_many_days = \
149
- current_month.remainder.same_remainder_divided_by_ten?(
150
- other: next_month.remainder.day
151
- )
152
- end
153
- end
154
- private_class_method :apply_big_and_small_of_the_month
155
-
156
- # :reek:TooManyStatements { max_statements: 10 }
157
-
158
- #
159
- # 閏月が存在した場合に以降の月を1つずつ減らす
160
- # @example 7,8,9 と続く月の8月が閏の場合、7, 閏7, 8 となる
161
- #
162
- # @param [Array<Month>] annual_range 1年データ
163
- #
164
- def self.adjust_leap_month(annual_range:)
165
- # 閏による月の再調整を行う
166
- leaped = false
167
- annual_range.each_with_index do |month, index|
168
- if month.even_term.invalid?
169
- month.leaped = true
170
- # NOTE: 初回閏月(閏11月)は前回月が存在しないため調整外
171
- leaped = true unless index.zero?
172
- end
173
- next unless leaped
174
-
175
- # NOTE: 常気法では閏月は2-3年に一度のため、1年に二度発生しない前提
176
- number = month.number - 1
177
- if number <= 0
178
- month.is_last_year = true
179
- number = 12
180
- end
181
- month.number = number
182
- end
183
- end
184
- private_class_method :adjust_leap_month
185
- end
186
- end
187
- end