zakuro 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) 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 +471 -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 +76 -0
  22. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +52 -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/merchant.rb +2 -2
  29. data/lib/zakuro/operation/month/parser.rb +1 -1
  30. data/lib/zakuro/operation/month/type.rb +5 -10
  31. data/lib/zakuro/output/error.rb +7 -6
  32. data/lib/zakuro/output/logger.rb +50 -49
  33. data/lib/zakuro/output/response.rb +145 -144
  34. data/lib/zakuro/tools/typeof.rb +2 -2
  35. data/lib/zakuro/version.rb +1 -1
  36. data/lib/zakuro/version/abstract_version.rb +1 -1
  37. data/lib/zakuro/version/context.rb +23 -0
  38. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  39. data/lib/zakuro/version/gihou/const/remainder.rb +56 -0
  40. data/lib/zakuro/version/gihou/cycle/remainder.rb +61 -0
  41. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  42. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  43. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  44. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  45. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  46. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  47. data/lib/zakuro/version/gihou/stella/lunar/location.rb +86 -0
  48. data/lib/zakuro/version/gihou/stella/lunar/value.rb +74 -0
  49. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  50. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  51. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  52. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  53. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  54. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  55. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  56. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  57. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  58. data/lib/zakuro/version/senmyou/const/remainder.rb +49 -0
  59. data/lib/zakuro/version/senmyou/cycle/remainder.rb +61 -0
  60. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +34 -0
  61. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +80 -195
  62. data/lib/zakuro/version/senmyou/range/annual_range.rb +25 -170
  63. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  64. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  65. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +44 -0
  66. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +93 -0
  67. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +66 -0
  68. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  69. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  70. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  71. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  72. data/lib/zakuro/version/senmyou/stella/solar/average.rb +97 -0
  73. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  74. data/lib/zakuro/version/senmyou/stella/solar/location.rb +61 -0
  75. data/lib/zakuro/version/senmyou/stella/solar/value.rb +39 -0
  76. data/lib/zakuro/version/version_class_resolver.rb +66 -0
  77. data/lib/zakuro/version_factory.rb +2 -2
  78. metadata +64 -24
  79. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  80. data/lib/zakuro/cycle/zodiac.rb +0 -103
  81. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  82. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  83. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -217
  84. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  85. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -86
  86. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  87. data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
  88. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -48
  89. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
  90. data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
  91. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -167
  92. data/lib/zakuro/version/senmyou/range/full_range.rb +0 -324
  93. data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -126
  94. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -181
  95. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -102
  96. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  97. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -214
  98. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -394
  99. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  100. data/lib/zakuro/version/senmyou/summary/single.rb +0 -125
@@ -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,86 +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
-
65
- #
66
- # データなしかを検証する
67
- #
68
- # @return [True] データなし
69
- # @return [False] データあり
70
- #
71
- def empty?
72
- (@index == -1 && @remainder.invalid?)
73
- end
74
-
75
- #
76
- # ディープコピー
77
- #
78
- # @param [SolarTerm] obj 自身
79
- #
80
- def initialize_copy(obj)
81
- @index = obj.index.clone
82
- @remainder = obj.remainder.clone
83
- end
84
- end
85
- end
86
- 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,48 +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
- #
41
- # 一ヶ月戻す
42
- #
43
- def back_to_last_month
44
- @is_last_year = true if month_label.back_to_last_month
45
- end
46
- end
47
- end
48
- end
@@ -1,181 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './first_day'
4
- require_relative './month_label'
5
-
6
- # TODO: moduleでMonthly とする(全暦むけに共通化したあと)
7
-
8
- # :nodoc:
9
- module Zakuro
10
- # :nodoc:
11
- module Senmyou
12
- #
13
- # Month 月情報
14
- #
15
- class Month
16
- # @return [MonthLabel] 月表示名
17
- attr_reader :month_label
18
- # @return [FirstDay] 月初日(朔日)
19
- attr_reader :first_day
20
- # @return [Array<SolarTerm>] 二十四節気
21
- attr_reader :solar_terms
22
-
23
- #
24
- # 初期化
25
- #
26
- # @param [MonthLabel] month_label 月表示名
27
- # @param [FirstDay] first_day 月初日(朔日)
28
- # @param [Array<SolarTerm>] solar_terms 二十四節気
29
- #
30
- def initialize(month_label: MonthLabel.new, first_day: FirstDay.new, solar_terms: [])
31
- @month_label = month_label
32
- @first_day = first_day
33
- @solar_terms = solar_terms
34
- end
35
-
36
- #
37
- # 中気なしは閏月とする
38
- #
39
- def eval_leaped
40
- leaped = even_term.invalid?
41
-
42
- @month_label = MonthLabel.new(number: number, is_many_days: many_days?, leaped: leaped)
43
- end
44
-
45
- #
46
- # 月初日の西暦日を返す
47
- #
48
- # @return [Western::Calendar] 西暦日
49
- #
50
- def western_date
51
- @first_day.western_date
52
- end
53
-
54
- #
55
- # 月初日の大余小余を返す
56
- #
57
- # @return [Remainder] 大余小余
58
- #
59
- def remainder
60
- @first_day.remainder
61
- end
62
-
63
- #
64
- # 月の大小を返す
65
- #
66
- # @return [True] 大の月(30日)
67
- # @return [False] 小の月(29日)
68
- #
69
- def many_days?
70
- @month_label.is_many_days
71
- end
72
-
73
- #
74
- # 月の日数を返す
75
- #
76
- # @return [Integer] 日数
77
- #
78
- def days
79
- @month_label.days
80
- end
81
-
82
- #
83
- # 月の名前(大小)を返す
84
- #
85
- # @return [String] 月の名前(大小)
86
- #
87
- def days_name
88
- @month_label.days_name
89
- end
90
-
91
- #
92
- # 月を返す
93
- #
94
- # @return [Integer] 月(xx月のxx)
95
- #
96
- def number
97
- @month_label.number
98
- end
99
-
100
- #
101
- # 閏を返す
102
- #
103
- # @return [True] 閏月
104
- # @return [False] 平月
105
- #
106
- def leaped?
107
- @month_label.leaped
108
- end
109
-
110
- #
111
- # 次月の大余から月の日数を定める
112
- #
113
- # @param [Integer] next_month_day 次月の大余
114
- #
115
- def eval_many_days(next_month_day:)
116
- is_many_days = remainder.same_remainder_divided_by_ten?(other: next_month_day)
117
-
118
- @month_label = MonthLabel.new(
119
- number: number, is_many_days: is_many_days, leaped: leaped?
120
- )
121
- end
122
-
123
- #
124
- # 二十四節気が未設定かどうかを検証する
125
- #
126
- # @return [True] 設定なし
127
- # @return [False] 設定あり
128
- #
129
- def empty_solar_term?
130
- @solar_terms.empty?
131
- end
132
-
133
- #
134
- # 中気を返す
135
- #
136
- # @return [SolarTerm] 中気
137
- #
138
- def even_term
139
- @solar_terms.each do |term|
140
- return term if term.index.even?
141
- end
142
-
143
- SolarTerm.new
144
- end
145
-
146
- #
147
- # 節気を返す
148
- #
149
- # @return [SolarTerm] 節気
150
- #
151
- def odd_term
152
- @solar_terms.each do |term|
153
- return term if term.index.odd?
154
- end
155
-
156
- SolarTerm.new
157
- end
158
-
159
- #
160
- # 二十四節気を追加する
161
- #
162
- # @param [SolarTerm] term 二十四節気
163
- #
164
- def add_term(term:)
165
- @solar_terms.push(term)
166
- end
167
-
168
- #
169
- # 同一の月情報かを検証する
170
- #
171
- # @param [Month] other 他の月情報
172
- #
173
- # @return [True] 同一の月
174
- # @return [False] 異なる月
175
- #
176
- def same?(other:)
177
- number == other.number && leaped? == other.leaped?
178
- end
179
- end
180
- end
181
- end