zakuro 0.1.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  3. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  4. data/lib/zakuro/calculation/base/year.rb +107 -0
  5. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +484 -0
  6. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
  7. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  8. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  9. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  10. data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
  11. data/lib/zakuro/calculation/monthly/month.rb +187 -0
  12. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  13. data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
  14. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  15. data/lib/zakuro/calculation/range/medieval_annual_range.rb +105 -0
  16. data/lib/zakuro/calculation/range/operated_range.rb +144 -0
  17. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  18. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
  19. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
  20. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  21. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +78 -0
  22. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +71 -0
  23. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +117 -0
  24. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +187 -0
  25. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +136 -0
  26. data/lib/zakuro/calculation/summary/single.rb +129 -0
  27. data/lib/zakuro/calculation/type/old_float.rb +69 -0
  28. data/lib/zakuro/era/japan/reki.rb +1 -1
  29. data/lib/zakuro/merchant.rb +2 -2
  30. data/lib/zakuro/output/error.rb +7 -6
  31. data/lib/zakuro/output/logger.rb +50 -49
  32. data/lib/zakuro/output/response.rb +145 -144
  33. data/lib/zakuro/tools/typeof.rb +2 -2
  34. data/lib/zakuro/version.rb +1 -1
  35. data/lib/zakuro/version/abstract_version.rb +1 -1
  36. data/lib/zakuro/version/context.rb +23 -0
  37. data/lib/zakuro/version/daien/const/number.rb +55 -0
  38. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  39. data/lib/zakuro/version/daien/cycle/remainder.rb +59 -0
  40. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  41. data/lib/zakuro/version/daien/daien.rb +36 -0
  42. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  43. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  44. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  45. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  46. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  47. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  48. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  49. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  50. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  51. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  52. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  53. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  54. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  55. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  56. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  57. data/lib/zakuro/version/gihou/const/remainder.rb +54 -0
  58. data/lib/zakuro/version/gihou/cycle/remainder.rb +56 -0
  59. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  60. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  61. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  62. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  63. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  64. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  65. data/lib/zakuro/version/gihou/stella/lunar/location.rb +80 -0
  66. data/lib/zakuro/version/gihou/stella/lunar/value.rb +75 -0
  67. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  68. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  69. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  70. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  71. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  72. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  73. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  74. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  75. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  76. data/lib/zakuro/version/senmyou/const/remainder.rb +47 -0
  77. data/lib/zakuro/version/senmyou/cycle/remainder.rb +56 -0
  78. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +34 -0
  79. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +80 -195
  80. data/lib/zakuro/version/senmyou/range/annual_range.rb +25 -145
  81. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  82. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  83. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +44 -0
  84. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +87 -0
  85. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +67 -0
  86. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  87. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  88. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  89. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  90. data/lib/zakuro/version/senmyou/stella/solar/average.rb +97 -0
  91. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  92. data/lib/zakuro/version/senmyou/stella/solar/location.rb +61 -0
  93. data/lib/zakuro/version/senmyou/stella/solar/value.rb +39 -0
  94. data/lib/zakuro/version/version_class_resolver.rb +70 -0
  95. data/lib/zakuro/version_factory.rb +3 -3
  96. metadata +83 -28
  97. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  98. data/lib/zakuro/cycle/zodiac.rb +0 -103
  99. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  100. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  101. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -217
  102. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  103. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -148
  104. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  105. data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
  106. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -119
  107. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
  108. data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
  109. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -196
  110. data/lib/zakuro/version/senmyou/range/full_range.rb +0 -194
  111. data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -126
  112. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -181
  113. data/lib/zakuro/version/senmyou/range/western_date_allocation.rb +0 -68
  114. data/lib/zakuro/version/senmyou/range/year_boundary.rb +0 -138
  115. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -102
  116. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  117. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -169
  118. data/lib/zakuro/version/senmyou/stella/solar_location.rb +0 -213
  119. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -213
  120. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  121. data/lib/zakuro/version/senmyou/summary/single.rb +0 -125
  122. data/lib/zakuro/version/taien/taien.rb +0 -19
@@ -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,148 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
-
4
- require_relative './remainder'
5
-
6
- # :nodoc:
7
- module Zakuro
8
- # :nodoc:
9
- module Senmyou
10
- #
11
- # SolarTerm 二十四節気
12
- #
13
- class SolarTerm
14
- # @return [Integer] 連番
15
- attr_reader :index
16
- # @return [Remainder] 時刻情報(大余小余)
17
- attr_reader :remainder
18
-
19
- # @return [Remainder] 気策(24分の1年)
20
- SOLAR_TERM_AVERAGE = Remainder.new(day: 15, minute: 1835, second: 5)
21
-
22
- # @return [Hash<Integer, Symbol>] 順序
23
- ORDER = {
24
- 0 => :touji,
25
- 1 => :shoukan,
26
- 2 => :daikan,
27
- 3 => :risshun,
28
- 4 => :usui,
29
- 5 => :keichitsu,
30
- 6 => :shunbun,
31
- 7 => :seimei,
32
- 8 => :kokuu,
33
- 9 => :rikka,
34
- 10 => :shouman,
35
- 11 => :boushu,
36
- 12 => :geshi,
37
- 13 => :shousho,
38
- 14 => :taisho,
39
- 15 => :risshuu,
40
- 16 => :shosho,
41
- 17 => :hakuro,
42
- 18 => :shuubun,
43
- 19 => :kanro,
44
- 20 => :soukou,
45
- 21 => :rittou,
46
- 22 => :shousetsu,
47
- 23 => :taisetsu
48
- }.freeze
49
-
50
- #
51
- # 初期化
52
- #
53
- # @param [Integer] index 連番
54
- # @param [Remainder] remainder 時刻情報(大余小余)
55
- #
56
- def initialize(index: -1, remainder: Remainder.new)
57
- @index = index
58
- @remainder = remainder
59
- end
60
-
61
- #
62
- # 不正かどうか検証する
63
- #
64
- # @return [True] 正しくない
65
- # @return [False] 正しい
66
- #
67
- def invalid?
68
- (@index == -1 || @remainder.invalid?)
69
- end
70
-
71
- #
72
- # データなしかを検証する
73
- #
74
- # @return [True] データなし
75
- # @return [False] データあり
76
- #
77
- def empty?
78
- (@index == -1 && @remainder.invalid?)
79
- end
80
-
81
- def index?(index)
82
- result = ORDER.fetch(index, -1)
83
-
84
- result != -1
85
- end
86
-
87
- #
88
- # 次の二十四節気に進める
89
- #
90
- def next!
91
- @index += 1
92
- @index = 0 if @index >= ORDER.size
93
-
94
- @remainder.add!(SOLAR_TERM_AVERAGE)
95
- end
96
-
97
- #
98
- # 指定した連番の二十四節気まで進める
99
- #
100
- # @param [Integer] index 連番
101
- #
102
- def next_by_index(index)
103
- return ArgumentError.new, 'invalid index' unless index?(index)
104
-
105
- loop do
106
- return if @index == index
107
-
108
- next!
109
- end
110
- end
111
-
112
- #
113
- # 指定した連番の二十四節気まで戻す
114
- #
115
- # @param [Integer] index 連番
116
- #
117
- def prev_by_index(index)
118
- return ArgumentError.new, 'invalid index' unless index?(index)
119
-
120
- loop do
121
- return if @index == index
122
-
123
- prev!
124
- end
125
- end
126
-
127
- #
128
- # 前の二十四節気に戻る
129
- #
130
- def prev!
131
- @index -= 1
132
- @index = 23 if @index.negative?
133
-
134
- @remainder.sub!(SOLAR_TERM_AVERAGE)
135
- end
136
-
137
- #
138
- # ディープコピー
139
- #
140
- # @param [SolarTerm] obj 自身
141
- #
142
- def initialize_copy(obj)
143
- @index = obj.index.clone
144
- @remainder = obj.remainder.clone
145
- end
146
- end
147
- end
148
- 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,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../../era/western'
4
-
5
- # TODO: moduleでMonthly とする(全暦むけに共通化したあと)
6
-
7
- # :nodoc:
8
- module Zakuro
9
- # :nodoc:
10
- module Senmyou
11
- #
12
- # FirstDay 月初日(朔日)
13
- #
14
- class FirstDay
15
- # @return [Western::Calendar] 西暦日
16
- attr_reader :western_date
17
- # @return [Remainder] 大余小余
18
- attr_reader :remainder
19
-
20
- #
21
- # 初期化
22
- #
23
- # @param [Remainder] remainder 西暦日
24
- # @param [Western::Calendar] western_date 大余小余
25
- #
26
- def initialize(western_date: Western::Calendar.new, remainder: Remainder.new)
27
- # 西暦日
28
- @western_date = western_date
29
- # 大余小余
30
- @remainder = remainder
31
- end
32
-
33
- #
34
- # ディープコピー
35
- #
36
- # @param [FirstDay] obj 自身
37
- #
38
- def initialize_copy(obj)
39
- @western_date = obj.western_date.clone
40
- @remainder = obj.remainder.clone
41
- end
42
- end
43
- end
44
- end
@@ -1,119 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './month'
4
-
5
- # TODO: moduleでMonthly とする(全暦むけに共通化したあと)
6
-
7
- # :nodoc:
8
- module Zakuro
9
- # :nodoc:
10
- module Senmyou
11
- #
12
- # InitializedMonth 初期月情報
13
- #
14
- class InitializedMonth < Month
15
- # @return [True] 昨年の月
16
- # @return [False] 今年の月
17
- # @note 冬至基準で1年データを作成するため昨年の11月-12月である可能性がある
18
- attr_reader :is_last_year
19
- # @return [Integer] 月齢(朔月、上弦、望月、下弦)
20
- attr_reader :phase_index
21
-
22
- # :reek:ControlParameter and :reek:BooleanParameter
23
-
24
- #
25
- # 初期化
26
- #
27
- # @param [MonthLabel] month_label 月表示名
28
- # @param [Array<SolarTerm>] solar_terms 二十四節気
29
- # @param [FirstDay] first_day 月初日(朔日)
30
- # @param [True, False] is_last_year 昨年の月/今年の月
31
- # @param [Integer] phase_index 月齢(朔月、上弦、望月、下弦)
32
- #
33
- def initialize(month_label: MonthLabel.new, solar_terms: [], first_day: FirstDay.new,
34
- is_last_year: false, phase_index: -1)
35
- super(month_label: month_label, solar_terms: solar_terms, first_day: first_day)
36
- @is_last_year = is_last_year
37
- @phase_index = phase_index
38
- end
39
-
40
- # :reek:TooManyStatements { max_statements: 6 }
41
-
42
- #
43
- # 現在の二十四節気に合わせて月表示情報を書き換える
44
- #
45
- def rename_month_label_by_solar_term
46
- return ArgumentError.new, 'solar term must not be empty.' if empty_solar_term?
47
-
48
- even = even_term
49
-
50
- is_many_days = month_label.is_many_days
51
- if even.invalid?
52
- @month_label = MonthLabel.new(
53
- number: InitializedMonth.month_number_by_odd_term_index(odd_term.index),
54
- leaped: true, is_many_days: is_many_days
55
- )
56
- return
57
- end
58
-
59
- @month_label = MonthLabel.new(
60
- number: InitializedMonth.month_number_by_even_term_index(even.index),
61
- leaped: false, is_many_days: is_many_days
62
- )
63
- end
64
-
65
- #
66
- # 中気の連番に合わせて月を返す
67
- #
68
- # @example
69
- # 20: 9月
70
- # 22: 10月
71
- # 0: 11月
72
- # 2: 12月
73
- # 4: 1月
74
- #
75
- # @param [Integer] index 中気番号
76
- #
77
- # @return [Integer] 月
78
- #
79
- def self.month_number_by_even_term_index(index)
80
- half_index = index / 2
81
-
82
- # 11月、12月
83
- return half_index + 11 if half_index < 2
84
-
85
- # 1月~10月
86
- half_index - 1
87
- end
88
-
89
- #
90
- # 節気の連番に合わせて月を返す
91
- #
92
- # @param [Integer] index 節気番号
93
- #
94
- # @return [Integer] 月
95
- #
96
- def self.month_number_by_odd_term_index(index)
97
- even_index = index - 1
98
-
99
- month_number_by_even_term_index(even_index)
100
- end
101
-
102
- #
103
- # 一ヶ月戻す
104
- #
105
- def back_to_last_month
106
- @is_last_year = true if month_label.back_to_last_month
107
- end
108
-
109
- #
110
- # 二十四節気の数を返す
111
- #
112
- # @return [Integer] 二十四節気の数
113
- #
114
- def solar_term_size
115
- solar_terms.size
116
- end
117
- end
118
- end
119
- end