zakuro 0.0.2 → 0.0.3

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: 6bd01ed3f0167a40a3c48e6c38c41b12229a0e46de4fb0c3fab8062ad81e74bf
4
- data.tar.gz: 9c9b86b6d3ac88a70c5eaafe432182408124bf69d87ec9d6c8194aab4eef5df5
3
+ metadata.gz: b9760966b2231b53988a9d909ac51c29ecaafbeddda486ebe204ad06c3ce1d70
4
+ data.tar.gz: e937ea0d241f429e674d9027e9a0a22643a01cd438f4b273988d2b5fdba6acda
5
5
  SHA512:
6
- metadata.gz: eaa23e0b9cb8622c181ecaecdcddaf6e31e22ebbf827fd3a2849f7085e65b37108fe4157fb4e2818102954f3fd89610345b05553674e0df15abf4be1cd5dc41a
7
- data.tar.gz: c58e2b2923d43b9ef882aff3d658108a6093b772f0fa4d2c2abb70c1ebb3313b111aed0aa84ba52e371bb6ab306365e6aaddbb0855b45ae82482f0a49b827c15
6
+ metadata.gz: 49be7726c71d135ff35331a30e3b8c892e6790cf9bab1a7d8dac8ee33aa8658421aa3f45604cf012d8ec76111389c15fc11ad0e2165bfb2c3a1ba1718151f190
7
+ data.tar.gz: 8c3eeecb97ffb39c7dc637c580d4478ae12e409d6d1f104596d00fbeba8ffbc81fe2c90d4c02b283d66ed8430c4d7c443a4f9ea5aec1710e2c89fa1132a07389
@@ -9,6 +9,9 @@ Layout/EndOfLine:
9
9
  Metrics/MethodLength:
10
10
  Max: 15
11
11
 
12
+ Naming/VariableNumber:
13
+ EnforcedStyle: snake_case
14
+
12
15
  # https://lkml.org/lkml/2020/5/29/1038
13
16
  Layout/LineLength:
14
17
  Max: 100
@@ -137,6 +137,7 @@ module Zakuro
137
137
  class Options
138
138
  # @return [Array<String>] オプション
139
139
  attr_reader :options
140
+
140
141
  #
141
142
  # 初期化
142
143
  #
@@ -35,15 +35,14 @@ module Zakuro
35
35
  #
36
36
  # 初期化
37
37
  #
38
+ # @param [Integer] base_day 1大余に必要な小余(暦によって基数が異なる)
39
+ # @param [Integer] base_mitune 1小余に必要な秒(暦によって基数が異なる)
38
40
  # @param [Integer] day 大余("日"に相当)
39
41
  # @param [Integer] minute 小余("分"に相当)
40
42
  # @param [Integer] second 秒
41
43
  # @param [Integer] total 繰り上げなしの小余
42
- # @param [Integer] base_day 1大余に必要な小余(暦によって基数が異なる)
43
- # @param [Integer] base_mitune 1小余に必要な秒(暦によって基数が異なる)
44
44
  #
45
- def initialize(day: -1, minute: -1, second: -1, total: -1,
46
- base_day:, base_mitune:)
45
+ def initialize(base_day:, base_mitune:, day: -1, minute: -1, second: -1, total: -1)
47
46
  @base_limit = LIMIT
48
47
  @base_day = base_day
49
48
  @base_minute = base_mitune
@@ -21,7 +21,7 @@ list:
21
21
  new_year_date: "1926-1-1"
22
22
  note: ""
23
23
  - name: "令和"
24
- # -
24
+ # 1年5月1日
25
25
  start_year: 1
26
26
  start_date: "2019-5-1"
27
27
  new_year_date: "2019-1-1"
@@ -89,6 +89,8 @@ module Zakuro
89
89
  end
90
90
  end
91
91
 
92
+ # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
93
+
92
94
  #
93
95
  # Gengou 元号情報
94
96
  #
@@ -269,6 +271,8 @@ module Zakuro
269
271
  SetParser.new(hash: yaml_hash).validate
270
272
  end
271
273
 
274
+ # :reek:TooManyInstanceVariables { max_instance_variables: 5 }
275
+
272
276
  #
273
277
  # GengouParser 元号情報の検証/展開を行う
274
278
  #
@@ -298,7 +302,7 @@ module Zakuro
298
302
  @start_year = hash['start_year']
299
303
  end
300
304
 
301
- # :reek:TooManyStatements { max_statements: 6 }
305
+ # :reek:TooManyStatements { max_statements: 7 }
302
306
 
303
307
  #
304
308
  # 検証する
@@ -604,7 +608,7 @@ module Zakuro
604
608
  return lines unless lines[0].invalid?
605
609
 
606
610
  first = Japan::Gengou.new
607
- lines[1..-1].each.with_index(1) do |item, index|
611
+ lines[1..].each.with_index(1) do |item, index|
608
612
  next if item.invalid?
609
613
 
610
614
  first = item
@@ -161,6 +161,11 @@ module Zakuro
161
161
  # Core 共通処理
162
162
  #
163
163
  class Core
164
+ #
165
+ # 初期化
166
+ #
167
+ def initialize(*_args); end
168
+
164
169
  #
165
170
  # ハッシュ化する
166
171
  #
@@ -210,6 +215,7 @@ module Zakuro
210
215
  # @param [Day] day 日
211
216
  #
212
217
  def initialize(year:, month:, day:)
218
+ super
213
219
  @year = year
214
220
  @month = month
215
221
  @day = day
@@ -3,5 +3,5 @@
3
3
  # :nodoc:
4
4
  module Zakuro
5
5
  # @return [String] library version
6
- VERSION = '0.0.2'
6
+ VERSION = '0.0.3'
7
7
  end
@@ -29,8 +29,8 @@ module Zakuro
29
29
  # @param [Integer] total 繰り上げなしの小余
30
30
  #
31
31
  def initialize(day: -1, minute: -1, second: -1, total: -1)
32
- super(day: day, minute: minute, second: second, total: total,
33
- base_day: DAY, base_mitune: MINUTE)
32
+ super(base_day: DAY, base_mitune: MINUTE,
33
+ day: day, minute: minute, second: second, total: total)
34
34
  end
35
35
  end
36
36
 
@@ -52,8 +52,8 @@ module Zakuro
52
52
  # @param [Integer] total 繰り上げなしの小余
53
53
  #
54
54
  def initialize(day: -1, minute: -1, second: -1, total: -1)
55
- super(day: day, minute: minute, second: second, total: total,
56
- base_day: DAY, base_mitune: MINUTE)
55
+ super(base_day: DAY, base_mitune: MINUTE,
56
+ day: day, minute: minute, second: second, total: total)
57
57
  end
58
58
  end
59
59
  end
@@ -145,7 +145,7 @@ module Zakuro
145
145
  # @return [Remainder] 定朔
146
146
  #
147
147
  def current_remainder
148
- debug('@average_remainder.format:' + @average_remainder.format)
148
+ debug("@average_remainder.format: #{@average_remainder.format}")
149
149
 
150
150
  sum = correction_value
151
151
  adjusted = @average_remainder.add(
@@ -193,7 +193,7 @@ module Zakuro
193
193
  { |key, _| key.match(/^#{prefix}_#{format('%<day>02d', day: day)}_.*/) }
194
194
 
195
195
  targets.each do |key, value|
196
- # NOTE 境界値は上から順に引き当てた方を返す(7日の境界値7465は上のキーで返す)
196
+ # NOTE: 境界値は上から順に引き当てた方を返す(7日の境界値7465は上のキーで返す)
197
197
  matched, diff = \
198
198
  extract_data_from_moon_adjustment_key(key, minute)
199
199
  # 小余の下げ幅
@@ -72,39 +72,53 @@ module Zakuro
72
72
  # @param [Array<Month>] annual_range 1年データ
73
73
  # @param [Array<Remainder>] solar_terms 1年データ内の全二十四節気
74
74
  #
75
- def self.apply_solar_terms_from_last_winter_solstice(annual_range:,
76
- solar_terms:)
77
-
78
- c_idx = 0
79
- st_idx = 0
75
+ def self.apply_solar_terms_from_last_winter_solstice(annual_range:, solar_terms:)
76
+ month_index = 0
77
+ solar_term_index = 0
80
78
  month_size = annual_range.size
81
79
 
82
- while c_idx < month_size && st_idx < solar_terms.size
83
- raise StandardError, "month is over. idx: #{c_idx}" if c_idx >= month_size
84
-
85
- current_month = annual_range[c_idx]
86
- next_month = annual_range[c_idx + 1]
87
- solar_term = solar_terms[st_idx]
80
+ while month_index < month_size && solar_term_index < solar_terms.size
81
+ raise StandardError, "month is over. idx: #{month_index}" if month_index >= month_size
88
82
 
89
- if in_range_solar_term?(target: solar_term, min: current_month.remainder,
90
- max: next_month.remainder)
91
- set_solar_term(month: current_month,
92
- solar_term: solar_term, solar_term_index: st_idx)
93
- st_idx += 1
83
+ if set_solar_term_on_current_month(current_month: annual_range[month_index],
84
+ next_month: annual_range[month_index + 1],
85
+ solar_term: solar_terms[solar_term_index],
86
+ solar_term_index: solar_term_index)
87
+ solar_term_index += 1
94
88
  next
95
89
  end
96
90
 
97
- # 一度も割り当てがない場合は二十四節気を進める
98
- if current_month.empty_solar_term?
99
- st_idx += 1
100
- next
101
- end
102
-
103
- c_idx += 1
91
+ month_index += 1
104
92
  end
105
93
  end
106
94
  private_class_method :apply_solar_terms_from_last_winter_solstice
107
95
 
96
+ #
97
+ # 当月に二十四節気を設定する
98
+ #
99
+ # @param [Remainder] current_month 当月
100
+ # @param [Month] next_month 次月
101
+ # @param [Month] solar_term 二十四節気
102
+ # @param [Integer] solar_term_index 二十四節気位置
103
+ #
104
+ # @return [True] 設定済
105
+ # @return [False] 未設定
106
+ #
107
+ def self.set_solar_term_on_current_month(current_month:,
108
+ next_month:, solar_term:, solar_term_index:)
109
+ if in_range_solar_term?(target: solar_term, min: current_month.remainder,
110
+ max: next_month.remainder)
111
+ set_solar_term(month: current_month,
112
+ solar_term: solar_term, solar_term_index: solar_term_index)
113
+ return true
114
+ end
115
+
116
+ # 一度も割り当てがない場合は設定済みとして次の二十四節気を進める
117
+ return true if current_month.empty_solar_term?
118
+
119
+ false
120
+ end
121
+
108
122
  #
109
123
  # 1年データ内の二十四節気の前後を収集する
110
124
  #
@@ -302,10 +302,8 @@ module Zakuro
302
302
  per_day = adjustment.per_day
303
303
  sign, ratio = calc_ratio(day: remainder.day, per_term: per_term, per_day: per_day)
304
304
 
305
- day_stack = calc_day_stack_from_ratio(sign: sign, ratio: ratio,
306
- minute: remainder.minute)
307
-
308
- day_stack
305
+ calc_day_stack_from_ratio(sign: sign, ratio: ratio,
306
+ minute: remainder.minute)
309
307
  end
310
308
  private_class_method :calc_day_stack
311
309
 
@@ -388,9 +386,7 @@ module Zakuro
388
386
  month_stack = stack + day * per_term + \
389
387
  (1 / 2.0) * (day * (day - 1) * per_day)
390
388
  # 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
391
- month_stack = month_stack.negative? ? month_stack.ceil : month_stack.floor
392
-
393
- month_stack
389
+ month_stack.negative? ? month_stack.ceil : month_stack.floor
394
390
  end
395
391
  private_class_method :calc_month_stack
396
392
  end
@@ -164,10 +164,11 @@ module Zakuro
164
164
  def self.adjust_leap_month(annual_range:)
165
165
  # 閏による月の再調整を行う
166
166
  leaped = false
167
- annual_range.each do |month|
167
+ annual_range.each_with_index do |month, index|
168
168
  if month.even_term.invalid?
169
169
  month.leaped = true
170
- leaped = true
170
+ # NOTE: 初回閏月(閏11月)は前回月が存在しないため調整外
171
+ leaped = true unless index.zero?
171
172
  end
172
173
  next unless leaped
173
174
 
@@ -20,9 +20,7 @@ module Zakuro
20
20
  # * 引き当てたい日付が元旦ではない場合、その月日に従い元号を再度求める
21
21
  # * この再計算が必要になるのは、元号が切り替わる年のみである
22
22
  class FullRange
23
- attr_reader :multi_gengou_roller
24
- attr_reader :new_year_date
25
- attr_reader :western_year
23
+ attr_reader :multi_gengou_roller, :new_year_date, :western_year
26
24
 
27
25
  # @return [Logger] ロガー
28
26
  LOGGER = Logger.new(location: 'full_range')
@@ -40,8 +38,7 @@ module Zakuro
40
38
  #
41
39
  def get
42
40
  years = FullRange.rearranged_years(annual_ranges: annual_ranges)
43
- years = update_gengou(years: years)
44
- years
41
+ update_gengou(years: years)
45
42
  end
46
43
 
47
44
  # :reek:TooManyStatements { max_statements: 6 }
@@ -115,6 +112,11 @@ module Zakuro
115
112
  #
116
113
  # 当年データを生成する
117
114
  #
115
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
116
+ # @param [Year] year 対象年
117
+ #
118
+ # @return [Year] 当年月ありの対象年
119
+ #
118
120
  def self.push_current_year(annual_range:, year: Year.new)
119
121
  annual_range.each do |month|
120
122
  next if month.is_last_year
@@ -126,7 +128,12 @@ module Zakuro
126
128
  end
127
129
 
128
130
  #
129
- # 当年データを生成する
131
+ # 昨年データを生成する
132
+ #
133
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
134
+ # @param [Year] year 対象年
135
+ #
136
+ # @return [Year] 昨年月ありの対象年
130
137
  #
131
138
  def self.push_last_year(annual_range:, year: Year.new)
132
139
  annual_range.each do |month|
@@ -142,6 +149,7 @@ module Zakuro
142
149
  # 年データの開始月を変更する
143
150
  #
144
151
  # @param [Array<Year>] annual_ranges 年データ(冬至基準)
152
+ # @param [Integer] index 対象年の要素番号
145
153
  #
146
154
  # @return [Year] 年データ(元旦基準)
147
155
  #
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.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - pldb
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-05 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: mainly lunar solar calendar
14
14
  email:
@@ -87,7 +87,7 @@ metadata:
87
87
  homepage_uri: https://github.com/pldb/zakuro
88
88
  source_code_uri: https://github.com/pldb/zakuro
89
89
  changelog_uri: https://github.com/pldb/zakuro
90
- post_install_message:
90
+ post_install_message:
91
91
  rdoc_options: []
92
92
  require_paths:
93
93
  - lib
@@ -102,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.1.2
106
- signing_key:
105
+ rubygems_version: 3.1.4
106
+ signing_key:
107
107
  specification_version: 4
108
108
  summary: japanese calendar library.
109
109
  test_files: []