zakuro 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e4972c48d6122814c2ce4f7b671948768cd2f7a8b977071c523cd982098ad35
4
- data.tar.gz: d5e5efd67f13ae70c453ff8095fe65c19c2dba8ec5213c3c6cedc166e7dfb7d4
3
+ metadata.gz: 2b346e15da34df44ce5692780edbd4b73a46161f8ab9c52a0a3b5e11708f60c9
4
+ data.tar.gz: 664d457a7e3a5a271073633bba9d2b85c94c1edc35d2ceaa5a0649d10c628202
5
5
  SHA512:
6
- metadata.gz: d7b235556dd510eeaff8b42712211b399c75ac6ce5ef3ac25812f7742f9da90e08c90bba7f4d6ba030c56d26d650df17ce802ed47cc30267874ffd25b97bc7b7
7
- data.tar.gz: 80ecbbe5e4b0d2428dc50f7fd8cdbf35e8667e0bbecc91d604541b4ee9dfdf72c2fb29ada37801c127719520f685520e973c3694ad149bc52f63d88b2fb83701
6
+ metadata.gz: 95779bea84d41f42027b8974742a924050c9b668f258a116d564b94991987ff5ac81554a6d8e518f8d7cc2bcd018eb9f082df6a997819d43fa475bfd3cd6f1bd
7
+ data.tar.gz: 4624affe06f638a930c36f80c357deb8ce311af730a67e2a296491efab1b3c648e3a5f5473b3f5fbfd6e9e088644bc7a29741204a9aac71517d1b4aef2dc3568
@@ -80,7 +80,15 @@ module Zakuro
80
80
  (@index == -1 && @remainder.invalid?)
81
81
  end
82
82
 
83
- def index?(index)
83
+ #
84
+ # 有効な二十四節気番号か
85
+ #
86
+ # @param [Integer] index 連番
87
+ #
88
+ # @return [True] 有効
89
+ # @return [False] 無効
90
+ #
91
+ def self.index?(index)
84
92
  result = ORDER.fetch(index, -1)
85
93
 
86
94
  result != -1
@@ -89,11 +97,18 @@ module Zakuro
89
97
  #
90
98
  # 次の二十四節気に進める
91
99
  #
92
- def next!
100
+ def next_term!
101
+ @remainder = next_term
102
+ end
103
+
104
+ #
105
+ # 次の二十四節気に進める
106
+ #
107
+ def next_term
93
108
  @index += 1
94
109
  @index = 0 if @index >= ORDER.size
95
110
 
96
- @remainder.add!(@average)
111
+ @remainder.add(@average)
97
112
  end
98
113
 
99
114
  #
@@ -102,7 +117,7 @@ module Zakuro
102
117
  # @param [Integer] index 連番
103
118
  #
104
119
  def next_by_index(index)
105
- return ArgumentError.new, 'invalid index' unless index?(index)
120
+ return ArgumentError.new, 'invalid index' unless AbstractSolarTerm.index?(index)
106
121
 
107
122
  loop do
108
123
  return if @index == index
@@ -117,23 +132,30 @@ module Zakuro
117
132
  # @param [Integer] index 連番
118
133
  #
119
134
  def prev_by_index(index)
120
- return ArgumentError.new, 'invalid index' unless index?(index)
135
+ return ArgumentError.new, 'invalid index' unless AbstractSolarTerm.index?(index)
121
136
 
122
137
  loop do
123
138
  return if @index == index
124
139
 
125
- prev!
140
+ prev_term!
126
141
  end
127
142
  end
128
143
 
129
144
  #
130
145
  # 前の二十四節気に戻る
131
146
  #
132
- def prev!
147
+ def prev_term!
148
+ @remainder = prev_term
149
+ end
150
+
151
+ #
152
+ # 前の二十四節気に戻る
153
+ #
154
+ def prev_term
133
155
  @index -= 1
134
156
  @index = 23 if @index.negative?
135
157
 
136
- @remainder.sub!(@average)
158
+ @remainder.sub(@average)
137
159
  end
138
160
 
139
161
  #
@@ -19,24 +19,29 @@ module Zakuro
19
19
  # @return [Integer] 月齢(朔月、上弦、望月、下弦)
20
20
  attr_reader :phase_index
21
21
 
22
- # :reek:ControlParameter and :reek:BooleanParameter
22
+ # :reek:BooleanParameter And :reek:LongParameterList {max_params: 6}
23
+ # rubocop:disable Metrics/ParameterLists
23
24
 
24
25
  #
25
26
  # 初期化
26
27
  #
28
+ # @param [Context] context 暦コンテキスト
27
29
  # @param [MonthLabel] month_label 月表示名
28
30
  # @param [Array<SolarTerm>] solar_terms 二十四節気
29
31
  # @param [FirstDay] first_day 月初日(朔日)
30
32
  # @param [True, False] is_last_year 昨年の月/今年の月
31
33
  # @param [Integer] phase_index 月齢(朔月、上弦、望月、下弦)
32
34
  #
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)
35
+ def initialize(context:, month_label: MonthLabel.new, solar_terms: [],
36
+ first_day: FirstDay.new, is_last_year: false, phase_index: -1)
37
+ super(context: context, month_label: month_label, solar_terms: solar_terms,
38
+ first_day: first_day)
36
39
  @is_last_year = is_last_year
37
40
  @phase_index = phase_index
38
41
  end
39
42
 
43
+ # rubocop:enable Metrics/ParameterLists
44
+
40
45
  # :reek:TooManyStatements { max_statements: 6 }
41
46
 
42
47
  #
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../cycle/abstract_solar_term'
4
-
5
3
  require_relative './first_day'
6
4
  require_relative './month_label'
7
5
 
@@ -15,6 +13,8 @@ module Zakuro
15
13
  # Month 月情報
16
14
  #
17
15
  class Month
16
+ # @return [Context] 暦コンテキスト
17
+ attr_reader :context
18
18
  # @return [MonthLabel] 月表示名
19
19
  attr_reader :month_label
20
20
  # @return [FirstDay] 月初日(朔日)
@@ -25,11 +25,14 @@ module Zakuro
25
25
  #
26
26
  # 初期化
27
27
  #
28
+ # @param [Context] context 暦コンテキスト
28
29
  # @param [MonthLabel] month_label 月表示名
29
30
  # @param [FirstDay] first_day 月初日(朔日)
30
31
  # @param [Array<SolarTerm>] solar_terms 二十四節気
31
32
  #
32
- def initialize(month_label: MonthLabel.new, first_day: FirstDay.new, solar_terms: [])
33
+ def initialize(context:, month_label: MonthLabel.new, first_day: FirstDay.new,
34
+ solar_terms: [])
35
+ @context = context
33
36
  @month_label = month_label
34
37
  @first_day = first_day
35
38
  @solar_terms = solar_terms
@@ -142,7 +145,7 @@ module Zakuro
142
145
  return term if term.index.even?
143
146
  end
144
147
 
145
- Cycle::AbstractSolarTerm.new
148
+ context.resolver.solar_term.new
146
149
  end
147
150
 
148
151
  #
@@ -155,7 +158,7 @@ module Zakuro
155
158
  return term if term.index.odd?
156
159
  end
157
160
 
158
- Cycle::AbstractSolarTerm.new
161
+ context.resolver.solar_term.new
159
162
  end
160
163
 
161
164
  #
@@ -20,22 +20,30 @@ module Zakuro
20
20
  # @return [OperatedSolarTerms] 運用時二十四節気
21
21
  attr_reader :operated_solar_terms
22
22
 
23
+ # :reek:LongParameterList {max_params: 6}
24
+ # rubocop:disable Metrics/ParameterLists
25
+
23
26
  #
24
27
  # 初期化
25
28
  #
29
+ # @param [Context] context 暦コンテキスト
26
30
  # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
27
31
  # @param [MonthLabel] month_label 月表示名
28
32
  # @param [FirstDay] first_day 月初日(朔日)
29
33
  # @param [Array<SolarTerm>] solar_terms 二十四節気
30
34
  # @param [Operation::MonthHistory] history 変更履歴(月)
31
35
  #
32
- def initialize(operated_solar_terms:, month_label: MonthLabel.new, first_day: FirstDay.new,
33
- solar_terms: [], history: Operation::MonthHistory.new)
34
- super(month_label: month_label, first_day: first_day, solar_terms: solar_terms)
36
+ def initialize(context:, operated_solar_terms:, month_label: MonthLabel.new,
37
+ first_day: FirstDay.new, solar_terms: [],
38
+ history: Operation::MonthHistory.new)
39
+ super(context: context, month_label: month_label, first_day: first_day,
40
+ solar_terms: solar_terms)
35
41
  @history = history
36
42
  @operated_solar_terms = operated_solar_terms
37
43
  end
38
44
 
45
+ # rubocop:enable Metrics/ParameterLists
46
+
39
47
  #
40
48
  # 書き換える
41
49
  #
@@ -176,7 +184,7 @@ module Zakuro
176
184
  def rewrite_remainder(days:)
177
185
  remainder = first_day.remainder.clone
178
186
  remainder.add!(
179
- Cycle::AbstractRemainder.new(day: days, minute: 0, second: 0)
187
+ context.resolver.remainder.new(day: days, minute: 0, second: 0)
180
188
  )
181
189
 
182
190
  remainder
@@ -30,6 +30,8 @@ module Zakuro
30
30
  # * この再計算が必要になるのは、元号が切り替わる年のみである
31
31
  #
32
32
  class FullRange
33
+ # @return [Context] 暦コンテキスト
34
+ attr_reader :context
33
35
  # @return [Western::Calendar] 開始日
34
36
  attr_reader :start_date
35
37
  # @return [Western::Calendar] 終了日
@@ -40,8 +42,6 @@ module Zakuro
40
42
  attr_reader :new_year_date
41
43
  # @return [Integer] 西暦年
42
44
  attr_reader :western_year
43
- # @return [Context] 暦コンテキスト
44
- attr_reader :context
45
45
 
46
46
  # @return [Output::Logger] ロガー
47
47
  LOGGER = Output::Logger.new(location: 'full_range')
@@ -85,12 +85,12 @@ module Zakuro
85
85
  return [] if invalid?
86
86
 
87
87
  years = Transfer::YearBoundary.get(
88
- annual_ranges: annual_ranges
88
+ context: @context, annual_ranges: annual_ranges
89
89
  )
90
90
  years = update_gengou(years: years)
91
91
 
92
92
  Transfer::WesternDateAllocation.update_first_day(
93
- years: years
93
+ context: @context, years: years
94
94
  )
95
95
 
96
96
  years
@@ -112,7 +112,7 @@ module Zakuro
112
112
  ((oldest_date.year)..(newest_date.year + 2)).each do |year|
113
113
  years.push(
114
114
  annual_range.collect_annual_range_after_last_november_1st(
115
- western_year: year
115
+ context: @context, western_year: year
116
116
  )
117
117
  )
118
118
  end
@@ -54,7 +54,8 @@ module Zakuro
54
54
 
55
55
  years.each do |year|
56
56
  operated_year = OperatedRange.rewrite_year(
57
- year: year, operated_solar_terms: @operated_solar_terms
57
+ context: context, year: year,
58
+ operated_solar_terms: @operated_solar_terms
58
59
  )
59
60
  operated_years.push(operated_year)
60
61
  end
@@ -65,18 +66,20 @@ module Zakuro
65
66
  #
66
67
  # 年を書き換える
67
68
  #
69
+ # @param [Context] context 暦コンテキスト
68
70
  # @param [Year] year 年
69
71
  # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
70
72
  #
71
73
  # @return [Year] 年
72
74
  #
73
- def self.rewrite_year(year:, operated_solar_terms:)
75
+ def self.rewrite_year(context:, year:, operated_solar_terms:)
74
76
  result = Base::Year.new(
75
77
  multi_gengou: year.multi_gengou, new_year_date: year.new_year_date
76
78
  )
77
79
  year.months.each do |month|
78
80
  result.push(month: resolve_month(
79
- month: month, operated_solar_terms: operated_solar_terms
81
+ context: context, month: month,
82
+ operated_solar_terms: operated_solar_terms
80
83
  ))
81
84
  end
82
85
 
@@ -88,34 +91,40 @@ module Zakuro
88
91
  #
89
92
  # 履歴情報の有無に応じた月にする
90
93
  #
94
+ # @param [Context] context 暦コンテキスト
91
95
  # @param [Month] month 月
92
96
  # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
93
97
  #
94
98
  # @return [Month] 月
95
99
  #
96
- def self.resolve_month(month:, operated_solar_terms:)
100
+ def self.resolve_month(context:, month:, operated_solar_terms:)
97
101
  history = Operation.specify_history(western_date: month.western_date)
98
102
 
99
103
  return month if history.invalid?
100
104
 
101
105
  OperatedRange.rewrite_month(
102
- month: month, history: history, operated_solar_terms: operated_solar_terms
106
+ context: context, month: month, history: history,
107
+ operated_solar_terms: operated_solar_terms
103
108
  )
104
109
  end
105
110
 
111
+ # :reek:LongParameterList {max_params: 4}
112
+
106
113
  #
107
114
  # 月を運用結果に書き換える
108
115
  #
116
+ # @param [Context] context 暦コンテキスト
109
117
  # @param [Month] month 月
110
118
  # @param [Operation::MonthHistory] history 変更履歴
111
119
  # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
112
120
  #
113
121
  # @return [Month] 月(運用結果)
114
122
  #
115
- def self.rewrite_month(month:, history:, operated_solar_terms:)
123
+ def self.rewrite_month(context:, month:, history:, operated_solar_terms:)
116
124
  return month unless month.western_date == history.western_date
117
125
 
118
126
  operated_month = Monthly::OperatedMonth.new(
127
+ context: context,
119
128
  month_label: month.month_label, first_day: month.first_day,
120
129
  solar_terms: month.solar_terms, history: history,
121
130
  operated_solar_terms: operated_solar_terms
@@ -124,6 +133,7 @@ module Zakuro
124
133
  operated_month.rewrite
125
134
 
126
135
  Monthly::Month.new(
136
+ context: context,
127
137
  month_label: operated_month.month_label, first_day: operated_month.first_day,
128
138
  solar_terms: operated_month.solar_terms
129
139
  )
@@ -15,12 +15,13 @@ module Zakuro
15
15
  #
16
16
  # 月初日の西暦日を更新する
17
17
  #
18
+ # @param [Context] context 暦コンテキスト
18
19
  # @param [Array<Year>] years 完全範囲(月初日なし)
19
20
  #
20
21
  # @return [Array<Year>] 完全範囲(月初日あり)
21
22
  #
22
- def self.get(years:)
23
- update_first_day(years: years)
23
+ def self.get(context:, years:)
24
+ update_first_day(context: context, years: years)
24
25
 
25
26
  years
26
27
  end
@@ -28,14 +29,16 @@ module Zakuro
28
29
  #
29
30
  # 月初日の西暦日を更新する
30
31
  #
32
+ # @param [Context] context 暦コンテキスト
31
33
  # @param [Array<Year>] years 完全範囲(月初日なし)
32
34
  #
33
- def self.update_first_day(years:)
35
+ def self.update_first_day(context:, years:)
34
36
  years.each_with_index do |year, index|
35
37
  new_year_date = year.new_year_date.clone
36
38
 
37
39
  months = year.months
38
40
  update_first_day_within_all_months(
41
+ context: context,
39
42
  new_year_date: new_year_date, months: months
40
43
  )
41
44
 
@@ -49,13 +52,16 @@ module Zakuro
49
52
  #
50
53
  # 全ての月で月初日の西暦日を更新する
51
54
  #
55
+ # @param [Context] context 暦コンテキスト
52
56
  # @param [Western::Calendar] new_year_date 元旦
53
57
  # @param [Array<Month>] months 月データ
54
58
  #
55
- def self.update_first_day_within_all_months(new_year_date:, months:)
59
+ def self.update_first_day_within_all_months(context:,
60
+ new_year_date:, months:)
56
61
  date = new_year_date.clone
57
62
  months.each_with_index do |month, index|
58
63
  updated_month = Monthly::Month.new(
64
+ context: context,
59
65
  month_label: month.month_label,
60
66
  first_day: Monthly::FirstDay.new(
61
67
  remainder: month.first_day.remainder,
@@ -20,12 +20,13 @@ module Zakuro
20
20
  #
21
21
  # 年間範囲内の年データの開始月を変更する
22
22
  #
23
+ # @param [Context] context 暦コンテキスト
23
24
  # @param [Array<Year>] annual_ranges 年データ(冬至基準)
24
25
  #
25
26
  # @return [Array<Year>] 年データ(元旦基準)
26
27
  #
27
- def self.get(annual_ranges:)
28
- categorize(annual_ranges: annual_ranges)
28
+ def self.get(context:, annual_ranges:)
29
+ categorize(context: context, annual_ranges: annual_ranges)
29
30
  rearranged_years(annual_ranges: annual_ranges)
30
31
  end
31
32
 
@@ -51,11 +52,12 @@ module Zakuro
51
52
  #
52
53
  # 年間範囲を昨年/今年で分類する
53
54
  #
55
+ # @param [Context] context 暦コンテキスト
54
56
  # @param [Array<Year>] annual_range 1年データ
55
57
  #
56
- def self.categorize(annual_ranges:)
58
+ def self.categorize(context:, annual_ranges:)
57
59
  annual_ranges.each do |annual_range|
58
- categorize_year(annual_range: annual_range)
60
+ categorize_year(context: context, annual_range: annual_range)
59
61
  end
60
62
  end
61
63
  private_class_method :categorize
@@ -63,14 +65,16 @@ module Zakuro
63
65
  #
64
66
  # 各月を昨年/今年で分類する
65
67
  #
68
+ # @param [Context] context 暦コンテキスト
66
69
  # @param [Array<Month>] annual_range 1年データ
67
70
  #
68
- def self.categorize_year(annual_range:)
71
+ def self.categorize_year(context:, annual_range:)
69
72
  is_last_year = true
70
73
  annual_range.each_with_index do |month, index|
71
74
  is_last_year = false if month.number == 1
72
75
 
73
76
  annual_range[index] = Monthly::InitializedMonth.new(
77
+ context: context,
74
78
  month_label: month.month_label, first_day: month.first_day,
75
79
  solar_terms: month.solar_terms, phase_index: month.phase_index,
76
80
  is_last_year: is_last_year
@@ -3,5 +3,5 @@
3
3
  # :nodoc:
4
4
  module Zakuro
5
5
  # @return [String] library version
6
- VERSION = '0.1.3'
6
+ VERSION = '0.1.4'
7
7
  end
@@ -62,12 +62,13 @@ module Zakuro
62
62
  # * 対象年に対して、前年11月-当年11月までを出力する
63
63
  # * 対象年(西暦)と計算年(元号x年)の紐付けは行わない
64
64
  #
65
+ # @param [Context] context 暦コンテキスト
65
66
  # @param [Integer] western_year 西暦年
66
67
  #
67
68
  # @return [Array<Month>] 1年データ
68
69
  #
69
- def self.collect_annual_range_after_last_november_1st(western_year:)
70
- annual_range = initialized_annual_range(western_year: western_year)
70
+ def self.collect_annual_range_after_last_november_1st(context:, western_year:)
71
+ annual_range = initialized_annual_range(context: context, western_year: western_year)
71
72
 
72
73
  apply_big_and_small_of_the_month(annual_range: annual_range)
73
74
 
@@ -111,11 +112,12 @@ module Zakuro
111
112
  #
112
113
  # 1年データを取得する
113
114
  #
115
+ # @param [Context] context 暦コンテキスト
114
116
  # @param [Integer] western_year 西暦年
115
117
  #
116
118
  # @return [Array<Month>] 1年データ
117
119
  #
118
- def self.initialized_annual_range(western_year:)
120
+ def self.initialized_annual_range(context:, western_year:)
119
121
  result = []
120
122
  lunar_phase = Monthly::LunarPhase.new(western_year: western_year)
121
123
 
@@ -125,6 +127,7 @@ module Zakuro
125
127
 
126
128
  result.push(
127
129
  Calculation::Monthly::InitializedMonth.new(
130
+ context: context,
128
131
  month_label: Calculation::Monthly::MonthLabel.new,
129
132
  first_day: Calculation::Monthly::FirstDay.new(remainder: adjusted),
130
133
  phase_index: 0
@@ -162,7 +162,7 @@ module Zakuro
162
162
  # 次の二十四節気に移る
163
163
  #
164
164
  def next_solar_term
165
- @solar_term.next!
165
+ @solar_term.next_term!
166
166
  end
167
167
  end
168
168
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zakuro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - pldb
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-01 00:00:00.000000000 Z
11
+ date: 2021-05-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: mainly lunar solar calendar
14
14
  email: