zakuro 0.4.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -3
  3. data/VERSION +1 -0
  4. data/doc/operation/csv/month.csv +21 -0
  5. data/doc/operation/operation.xlsx +0 -0
  6. data/lib/zakuro/calculation/base/gengou.rb +82 -0
  7. data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
  8. data/lib/zakuro/calculation/base/operated_year.rb +5 -15
  9. data/lib/zakuro/calculation/base/year.rb +26 -14
  10. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +0 -13
  11. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
  12. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
  13. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
  14. data/lib/zakuro/calculation/era/gengou/internal/reserve/list.rb +244 -0
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/range.rb +193 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +42 -0
  17. data/lib/zakuro/calculation/era/gengou/scroll.rb +211 -0
  18. data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
  19. data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
  20. data/lib/zakuro/calculation/era/version/version.rb +24 -0
  21. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  22. data/lib/zakuro/calculation/monthly/month.rb +49 -2
  23. data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
  24. data/lib/zakuro/calculation/range/full_range.rb +68 -107
  25. data/lib/zakuro/calculation/range/operated_range.rb +13 -9
  26. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
  27. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  28. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  29. data/lib/zakuro/calculation/specifier/internal/month.rb +84 -0
  30. data/lib/zakuro/calculation/specifier/multiple_day.rb +162 -0
  31. data/lib/zakuro/calculation/specifier/single_day.rb +15 -37
  32. data/lib/zakuro/calculation/summary/internal/operation.rb +98 -0
  33. data/lib/zakuro/calculation/summary/range.rb +120 -0
  34. data/lib/zakuro/calculation/summary/single.rb +45 -64
  35. data/lib/zakuro/condition.rb +14 -0
  36. data/lib/zakuro/era/japan/calendar.rb +133 -0
  37. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +106 -0
  38. data/lib/zakuro/era/japan/gengou/alignment/division.rb +165 -0
  39. data/lib/zakuro/era/japan/gengou/alignment/line.rb +156 -0
  40. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +184 -0
  41. data/lib/zakuro/era/japan/gengou/alignment.rb +42 -0
  42. data/lib/zakuro/era/japan/gengou/resource/parser.rb +242 -0
  43. data/lib/zakuro/era/japan/gengou/resource/type.rb +292 -0
  44. data/lib/zakuro/era/japan/gengou/resource/validator.rb +346 -0
  45. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
  46. data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
  47. data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
  48. data/lib/zakuro/era/japan/gengou/resource.rb +32 -0
  49. data/lib/zakuro/era/japan/gengou.rb +35 -74
  50. data/lib/zakuro/era/japan/version.rb +151 -0
  51. data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
  52. data/lib/zakuro/merchant.rb +50 -3
  53. data/lib/zakuro/operation/month/parser.rb +1 -1
  54. data/lib/zakuro/operation/month/type.rb +1 -1
  55. data/lib/zakuro/operation/month/validator.rb +2 -2
  56. data/lib/zakuro/operation/yaml/month.yaml +672 -0
  57. data/lib/zakuro/output/response.rb +5 -5
  58. data/lib/zakuro/result/result.rb +17 -0
  59. data/lib/zakuro/tools/typeconv.rb +38 -0
  60. data/lib/zakuro/tools/typeof.rb +4 -1
  61. data/lib/zakuro/version/context.rb +24 -3
  62. data/lib/zakuro/version/daien/cycle/remainder.rb +26 -0
  63. data/lib/zakuro/version/daien/daien.rb +1 -26
  64. data/lib/zakuro/version/daien/stella/solar/average.rb +2 -2
  65. data/lib/zakuro/version/genka/const/number.rb +43 -0
  66. data/lib/zakuro/version/genka/const/remainder.rb +33 -0
  67. data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
  68. data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
  69. data/lib/zakuro/version/genka/genka.rb +1 -9
  70. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
  71. data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
  72. data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
  73. data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
  74. data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
  75. data/lib/zakuro/version/gihou/cycle/remainder.rb +26 -0
  76. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  77. data/lib/zakuro/version/gihou/stella/solar/average.rb +2 -2
  78. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  79. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  80. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  81. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  82. data/lib/zakuro/version/senmyou/README.md +11 -7
  83. data/lib/zakuro/version/senmyou/cycle/remainder.rb +26 -0
  84. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  85. data/lib/zakuro/version/senmyou/stella/solar/average.rb +2 -2
  86. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  87. data/lib/zakuro/version/version_class_resolver.rb +4 -0
  88. data/zakuro.gemspec +1 -3
  89. metadata +45 -16
  90. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  91. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  92. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  93. data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
  94. data/lib/zakuro/era/japan/gengou/type.rb +0 -178
  95. data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
  96. data/lib/zakuro/era/japan/reki.rb +0 -91
  97. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  98. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  99. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  100. data/lib/zakuro/version/abstract_version.rb +0 -29
  101. data/lib/zakuro/version.rb +0 -7
  102. data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,50 @@
1
+ ---
2
+ id: 3
3
+ name: 近代(一世一元)
4
+ last_year:
5
+ japan: 7981
6
+ western: 9999
7
+ last_date:
8
+ japan: 令和7981年12月31日
9
+ western: '9999-12-31'
10
+ list:
11
+ - name: 明治
12
+ start_year:
13
+ japan: 1
14
+ western: 1868
15
+ start_date:
16
+ japan: 明治01年09月08日
17
+ western: '1868-10-23'
18
+ disuse:
19
+ new_year_date: '1868-1-25'
20
+ note: ''
21
+ - name: 大正
22
+ start_year:
23
+ japan: 1
24
+ western: 1912
25
+ start_date:
26
+ japan: 大正01年07月30日
27
+ western: '1912-7-30'
28
+ disuse:
29
+ new_year_date: '1912-1-1'
30
+ note: ''
31
+ - name: 昭和
32
+ start_year:
33
+ japan: 1
34
+ western: 1926
35
+ start_date:
36
+ japan: 昭和01年12月25日
37
+ western: '1926-12-25'
38
+ disuse:
39
+ new_year_date: '1926-1-1'
40
+ note: ''
41
+ - name: 令和
42
+ start_year:
43
+ japan: 1
44
+ western: 2019
45
+ start_date:
46
+ japan: 令和01年05月01日
47
+ western: '2019-5-1'
48
+ disuse:
49
+ new_year_date: '2019-1-1'
50
+ note: ''
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './resource/parser'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ #
8
+ # Japan 和暦
9
+ #
10
+ module Japan
11
+ #
12
+ # Resource yaml解析結果
13
+ #
14
+ module Resource
15
+ # @return [Array<Set>] 元号セット情報リスト
16
+ LIST = [
17
+ Parser.run(filepath: File.expand_path(
18
+ './resource/yaml/set-001-until-south.yaml',
19
+ __dir__
20
+ )),
21
+ Parser.run(filepath: File.expand_path(
22
+ './resource/yaml/set-002-from-north.yaml',
23
+ __dir__
24
+ )),
25
+ Parser.run(filepath: File.expand_path(
26
+ './resource/yaml/set-003-modern.yaml',
27
+ __dir__
28
+ ))
29
+ ].freeze
30
+ end
31
+ end
32
+ end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../western'
4
- require_relative './gengou/parser'
5
- require_relative './gengou/type'
3
+ require_relative '../western/calendar'
4
+
5
+ require_relative './gengou/alignment'
6
6
 
7
7
  # :nodoc:
8
8
  module Zakuro
@@ -11,95 +11,56 @@ module Zakuro
11
11
  #
12
12
  module Japan
13
13
  #
14
- # GengouResource 元号情報
14
+ # Gengou 元号
15
15
  #
16
- module GengouResource
17
- # @return [Array<Set>] 元号セット情報リスト
18
- LIST = [
19
- Parser.run(filepath: File.expand_path(
20
- './yaml/set-001-until-south.yaml',
21
- __dir__
22
- )),
23
- Parser.run(filepath: File.expand_path(
24
- './yaml/set-002-from-north.yaml',
25
- __dir__
26
- )),
27
- Parser.run(filepath: File.expand_path(
28
- './yaml/set-003-modern.yaml',
29
- __dir__
30
- ))
31
- ].freeze
32
-
33
- # :reek:TooManyStatements { max_statements: 9 }
34
-
35
- #
36
- # 元号(1行目,2行目)を引き当てる
37
- #
38
- # * LINE配列の元号情報を配列順で「x行目」(1始まり)とする
39
- # * 1行目にデータがあれば、第一要素に1行目のデータが設定される
40
- # * 1行目と2行目にデータがあれば、第二要素に2行目のデータが設定される
41
- # * 1行目にデータがなく、2行目以降に1つだけデータがあれば、第一要素にそのデータを設定してそれ以外の要素は未設定
42
- # * 1行目にデータがなく、2行目以降に2つ以上のデータがあれば、第一要素に末尾行に一番近いデータを設定してそれ以外の要素は未設定
43
- #
44
- # @param [Western::Calendar] date 日
45
- #
46
- # @return [Array<Gengou>] 元号情報(1行目, 2行目)
47
- #
48
- def self.lines(date:)
49
- lines = native_lines(date: date)
50
- return lines unless lines[0].invalid?
51
-
52
- first = Japan::Gengou.new
53
- lines[1..].each.with_index(1) do |item, index|
54
- next if item.invalid?
16
+ module Gengou
17
+ # @return [Integer] 1行目
18
+ FIRST_LINE = Alignment::Aligner::FIRST_LINE
19
+ # @return [Integer] 2行目
20
+ SECOND_LINE = Alignment::Aligner::SECOND_LINE
55
21
 
56
- first = item
57
- lines[index] = Japan::Gengou.new
58
- end
59
- lines[0] = first
60
- lines
61
- end
62
-
63
- #
64
- # 元号を引き当てる
65
22
  #
66
- # * LISTから単純に元号を引き当てる
67
- # * 1行目,2行目といった概念は無視する
23
+ # 該当行の元号を取得する
68
24
  #
69
- # @param [Western::Calendar] date
25
+ # @param [Integer] line 行番号
26
+ # @param [Western::Calendar] start_date 開始日
27
+ # @param [Western::Calendar] last_date 終了日
70
28
  #
71
- # @return [Array<Gengou>] 元号情報
29
+ # @return [Array<LinearGengou>] 該当行の元号
72
30
  #
73
- def self.native_lines(date:)
74
- result = Array.new(LIST.size)
75
- LIST.each_with_index do |set, index|
76
- result[index] = set.include_item(date: date)
77
- end
78
- result
31
+ def self.line(line: FIRST_LINE,
32
+ start_date: Western::Calendar.new, last_date: Western::Calendar.new)
33
+ Alignment.get(
34
+ line: line, start_date: start_date, last_date: last_date
35
+ )
79
36
  end
80
37
 
81
38
  #
82
- # 「日本暦日原典」1行目の元号を返す
39
+ # 1行目元号を取得する
83
40
  #
84
- # @param [Western::Calendar] date
41
+ # @param [Western::Calendar] start_date 開始日
42
+ # @param [Western::Calendar] last_date 終了日
85
43
  #
86
- # @return [Gengou] 元号情報(1行目)
44
+ # @return [Array<LinearGengou>] 1行目元号
87
45
  #
88
- def self.first_line(date:)
89
- lines = lines(date: date)
90
- lines[0].clone
46
+ def self.first_line(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
47
+ Alignment.get(
48
+ line: FIRST_LINE, start_date: start_date, last_date: last_date
49
+ )
91
50
  end
92
51
 
93
52
  #
94
- # 「日本暦日原典」2行目の元号を返す
53
+ # 2行目元号を取得する
95
54
  #
96
- # @param [Western::Calendar] date
55
+ # @param [Western::Calendar] start_date 開始日
56
+ # @param [Western::Calendar] last_date 終了日
97
57
  #
98
- # @return [Gengou] 元号情報(2行目)
58
+ # @return [Array<LinearGengou>] 2行目元号
99
59
  #
100
- def self.second_line(date:)
101
- lines = lines(date: date)
102
- lines[1].clone
60
+ def self.second_line(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
61
+ Alignment.get(
62
+ line: SECOND_LINE, start_date: start_date, last_date: last_date
63
+ )
103
64
  end
104
65
  end
105
66
  end
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../western/calendar'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ #
8
+ # Japan 和暦
9
+ #
10
+ module Japan
11
+ #
12
+ # Version 暦
13
+ #
14
+ module Version
15
+ #
16
+ # Range 暦(範囲)
17
+ #
18
+ class Range
19
+ # @return [String] 暦名
20
+ attr_reader :name
21
+ # @return [Western::Calendar] 暦の開始日
22
+ attr_reader :start_date
23
+ # @return [Integer] 開始西暦年
24
+ attr_reader :start_year
25
+ # @return [Integer] 終了西暦年
26
+ attr_reader :last_year
27
+ # @return [True] リリース済
28
+ # @return [False] 未リリース
29
+ attr_reader :released
30
+
31
+ #
32
+ # 初期化
33
+ #
34
+ # @param [String] name 暦名
35
+ # @param [Western::Calendar] start_date 暦の開始日
36
+ # @param [Integer] start_year 開始西暦年
37
+ # @param [Integer] last_year 終了西暦年
38
+ # @param [True, False] released リリース済 / 未リリース
39
+ #
40
+ def initialize(name:, start_date:, start_year:, last_year:, released:)
41
+ @name = name
42
+ @start_date = start_date
43
+ @start_year = start_year
44
+ @last_year = last_year
45
+ @released = released
46
+ end
47
+ end
48
+
49
+ # TODO: yamlにする
50
+ # TODO: last_year は不要
51
+
52
+ # @return [Array<Range>] 全和暦
53
+ LIST = [
54
+ # 允恭天皇34年01月01日
55
+ Range.new(
56
+ name: 'Genka',
57
+ start_date: Western::Calendar.new(year: 445, month: 1, day: 24),
58
+ start_year: 445,
59
+ last_year: 697,
60
+ released: true
61
+ ),
62
+ # 文武天皇02年01月01日
63
+ Range.new(
64
+ name: 'Gihou',
65
+ start_date: Western::Calendar.new(year: 698, month: 2, day: 16),
66
+ start_year: 698,
67
+ last_year: 763,
68
+ released: true
69
+ ),
70
+ # 天平宝字08年01月01日
71
+ Range.new(
72
+ name: 'Daien',
73
+ start_date: Western::Calendar.new(year: 764, month: 2, day: 7),
74
+ start_year: 764,
75
+ last_year: 861,
76
+ released: true
77
+ ),
78
+ # 貞観02年01月01日
79
+ Range.new(
80
+ name: 'Senmyou',
81
+ start_date: Western::Calendar.new(year: 862, month: 2, day: 3),
82
+ start_year: 862,
83
+ last_year: 1684,
84
+ released: true
85
+ ),
86
+ # 貞享02年01月01日
87
+ Range.new(
88
+ name: 'Joukyou',
89
+ start_date: Western::Calendar.new(year: 1685, month: 2, day: 4),
90
+ start_year: 1685,
91
+ last_year: 1754,
92
+ released: false
93
+ ),
94
+ # 宝暦05年01月01日
95
+ Range.new(
96
+ name: 'Houryaku',
97
+ start_date: Western::Calendar.new(year: 1755, month: 2, day: 11),
98
+ start_year: 1755,
99
+ last_year: 1797,
100
+ released: false
101
+ ),
102
+ # 寛政10年01月01日
103
+ Range.new(
104
+ name: 'Kansei',
105
+ start_date: Western::Calendar.new(year: 1798, month: 2, day: 16),
106
+ start_year: 1798,
107
+ last_year: 1843,
108
+ released: false
109
+ ),
110
+ # 天保13年01月01日
111
+ Range.new(
112
+ name: 'Tenpou',
113
+ start_date: Western::Calendar.new(year: 1844, month: 2, day: 18),
114
+ start_year: 1844,
115
+ last_year: 1867,
116
+ released: false
117
+ ),
118
+ # 明治01年09月08日
119
+ Range.new(
120
+ name: 'Gregorio',
121
+ start_date: Western::Calendar.new(year: 1868, month: 10, day: 23),
122
+ start_year: 1868,
123
+ last_year: 9999,
124
+ released: false
125
+ )
126
+ ].freeze
127
+
128
+ #
129
+ # 年を基準に暦を引き当てる
130
+ #
131
+ # @param [Integer] start_year 開始西暦年
132
+ # @param [Integer] last_year 終了西暦年
133
+ #
134
+ # @return [Array<Range>] 和暦
135
+ #
136
+ def self.ranges_with_year(start_year:, last_year:)
137
+ result = []
138
+
139
+ LIST.each do |range|
140
+ next if start_year > range.last_year
141
+
142
+ next if last_year < range.start_year
143
+
144
+ result.push(range)
145
+ end
146
+
147
+ result
148
+ end
149
+ end
150
+ end
151
+ end
File without changes
@@ -1,6 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './version_factory'
3
+ require_relative './era/western/calendar'
4
+
5
+ require_relative './calculation/summary/single'
6
+
7
+ require_relative './calculation/summary/range'
8
+
4
9
  require_relative './condition'
5
10
 
6
11
  require_relative './output/error'
@@ -47,13 +52,55 @@ module Zakuro
47
52
  # 承諾する
48
53
  #
49
54
  # @return [Result::SingleDay] 和暦日
55
+ # @return [Result::Range] 和暦日範囲
50
56
  #
51
57
  def commit
52
58
  date = condition.date
53
- return VersionFactory.to_japan_date(western_date: date) if date
54
59
 
55
- # TODO: does not have no patterns now
60
+ return single(date: date) if date
61
+
62
+ range = condition.range
63
+
64
+ return range(range: range) if range
65
+
56
66
  {}
57
67
  end
68
+
69
+ private
70
+
71
+ #
72
+ # 1日検索
73
+ #
74
+ # @param [Date] date 西暦日
75
+ #
76
+ # @return [Result::Single] 検索結果
77
+ #
78
+ def single(date:)
79
+ western_date = Western::Calendar.create(date: date)
80
+
81
+ # TODO: condition で設定する
82
+ context = Context.new(version_name: '')
83
+
84
+ Calculation::Summary::Single.get(context: context, date: western_date)
85
+ end
86
+
87
+ #
88
+ # 期間検索
89
+ #
90
+ # @param [Catalog::Range] range 期間
91
+ #
92
+ # @return [Result::Range] 和暦日範囲
93
+ #
94
+ def range(range:)
95
+ start_date = Western::Calendar.create(date: range[:start])
96
+ last_date = Western::Calendar.create(date: range[:last])
97
+
98
+ # TODO: condition で設定する
99
+ context = Context.new(version_name: '')
100
+
101
+ Calculation::Summary::Range.get(
102
+ context: context, start_date: start_date, last_date: last_date
103
+ )
104
+ end
58
105
  end
59
106
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
- require_relative '../../era/western'
4
+ require_relative '../../era/western/calendar'
5
5
  require_relative './validator'
6
6
  require_relative './type'
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
- require_relative '../../era/western'
4
+ require_relative '../../era/western/calendar'
5
5
  require_relative './validator'
6
6
 
7
7
  # :nodoc:
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
- require_relative '../../era/western'
4
+ require_relative '../../era/western/calendar'
5
5
 
6
6
  # :nodoc:
7
7
  module Zakuro
@@ -150,7 +150,7 @@ module Zakuro
150
150
  # @return [String] ID
151
151
  attr_reader :id
152
152
  # @return [String] 親ID
153
- attr_reader :parend_id
153
+ attr_reader :parent_id
154
154
  # @return [String] 西暦日
155
155
  attr_reader :western_date
156
156
  # @return [String] 有効行