zakuro 0.6.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +58 -16
  4. data/VERSION +1 -1
  5. data/doc/dropped_date.md +93 -0
  6. data/doc/error.md +45 -0
  7. data/doc/operation/transfer.rb +8 -8
  8. data/lib/zakuro/calculation/base/day.rb +52 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +50 -4
  10. data/lib/zakuro/calculation/base/linear_gengou.rb +6 -6
  11. data/lib/zakuro/calculation/base/operated_year.rb +3 -3
  12. data/lib/zakuro/calculation/base/year.rb +4 -4
  13. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +5 -3
  14. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +209 -0
  15. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
  17. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +230 -0
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +193 -0
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
  26. data/lib/zakuro/calculation/{gengou → era/gengou}/internal/reserve.rb +6 -7
  27. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  28. data/lib/zakuro/calculation/{version → era/version}/internal/crawler.rb +7 -7
  29. data/lib/zakuro/calculation/{version → era/version}/internal/range.rb +4 -4
  30. data/lib/zakuro/calculation/{version → era/version}/version.rb +3 -3
  31. data/lib/zakuro/calculation/monthly/initialized_month.rb +1 -1
  32. data/lib/zakuro/calculation/monthly/month.rb +44 -5
  33. data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
  34. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  35. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  36. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +29 -27
  37. data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +11 -14
  38. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  39. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  40. data/lib/zakuro/calculation/range/medieval_annual_range.rb +2 -2
  41. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  42. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  43. data/lib/zakuro/calculation/range/operated_solar_terms.rb +9 -11
  44. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +6 -6
  45. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +2 -0
  46. data/lib/zakuro/calculation/summary/internal/day.rb +40 -0
  47. data/lib/zakuro/calculation/summary/internal/month.rb +92 -0
  48. data/lib/zakuro/calculation/summary/{single.rb → internal/operation.rb} +6 -40
  49. data/lib/zakuro/calculation/summary/internal/option.rb +85 -0
  50. data/lib/zakuro/calculation/summary/japan/range.rb +158 -0
  51. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  52. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +96 -0
  53. data/lib/zakuro/calculation/summary/western/range.rb +124 -0
  54. data/lib/zakuro/calculation/summary/western/single.rb +113 -0
  55. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +174 -0
  56. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +98 -0
  57. data/lib/zakuro/calculation/type/optional.rb +46 -0
  58. data/lib/zakuro/condition.rb +75 -22
  59. data/lib/zakuro/context/context.rb +44 -0
  60. data/lib/zakuro/context/option.rb +117 -0
  61. data/lib/zakuro/context/version_class_resolver.rb +110 -0
  62. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +125 -0
  63. data/lib/zakuro/era/japan/gengou/alignment/division.rb +168 -0
  64. data/lib/zakuro/era/japan/gengou/alignment/line.rb +175 -0
  65. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +187 -0
  66. data/lib/zakuro/era/japan/gengou/alignment.rb +55 -0
  67. data/lib/zakuro/era/japan/gengou/resource/parser.rb +245 -0
  68. data/lib/zakuro/era/japan/gengou/resource/type.rb +299 -0
  69. data/lib/zakuro/era/japan/gengou/resource/validator.rb +347 -0
  70. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-001-until-south.yaml +2 -2
  71. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-002-from-north.yaml +2 -2
  72. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-003-modern.yaml +2 -2
  73. data/lib/zakuro/era/japan/gengou/resource.rb +33 -0
  74. data/lib/zakuro/era/japan/gengou.rb +25 -79
  75. data/lib/zakuro/era/japan/version.rb +18 -18
  76. data/lib/zakuro/era/western/calendar.rb +13 -9
  77. data/lib/zakuro/exception/case/pattern.rb +71 -0
  78. data/lib/zakuro/exception/case/preset.rb +51 -0
  79. data/lib/zakuro/exception/case/template.rb +48 -0
  80. data/lib/zakuro/exception/cause.rb +28 -0
  81. data/lib/zakuro/exception/exception.rb +37 -0
  82. data/lib/zakuro/exception/zakuro_error.rb +46 -0
  83. data/lib/zakuro/gateway/locale/date.rb +127 -0
  84. data/lib/zakuro/gateway/locale/range.rb +67 -0
  85. data/lib/zakuro/gateway/range.rb +99 -0
  86. data/lib/zakuro/gateway/single.rb +70 -0
  87. data/lib/zakuro/merchant.rb +84 -12
  88. data/lib/zakuro/operation/month/parser.rb +11 -9
  89. data/lib/zakuro/operation/month/type.rb +31 -31
  90. data/lib/zakuro/operation/month/validator.rb +50 -50
  91. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  92. data/lib/zakuro/output/logger.rb +17 -3
  93. data/lib/zakuro/output/response.rb +24 -57
  94. data/lib/zakuro/result/data/day.rb +43 -0
  95. data/lib/zakuro/result/data/gengou.rb +35 -0
  96. data/lib/zakuro/result/data/month.rb +63 -0
  97. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  98. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  99. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  100. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  101. data/lib/zakuro/result/data/single_day.rb +56 -0
  102. data/lib/zakuro/result/data/solar_term.rb +35 -0
  103. data/lib/zakuro/result/data/year.rb +45 -0
  104. data/lib/zakuro/result/operation/bundle.rb +44 -0
  105. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  106. data/lib/zakuro/result/operation/month/bundle.rb +36 -0
  107. data/lib/zakuro/result/operation/month/history.rb +54 -0
  108. data/lib/zakuro/result/result.rb +21 -2
  109. data/lib/zakuro/tools/stringifier.rb +26 -3
  110. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  111. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  112. data/lib/zakuro/version/daien/range/annual_range.rb +1 -1
  113. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +2 -0
  114. data/lib/zakuro/version/daien/stella/lunar/value.rb +2 -0
  115. data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
  116. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  117. data/lib/zakuro/version/genka/range/annual_range.rb +1 -1
  118. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  119. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  120. data/lib/zakuro/version/gihou/range/annual_range.rb +1 -1
  121. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +2 -0
  122. data/lib/zakuro/version/gihou/stella/lunar/value.rb +2 -0
  123. data/lib/zakuro/version/senmyou/README.md +11 -7
  124. data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
  125. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  126. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  127. data/lib/zakuro/version/senmyou/range/annual_range.rb +1 -1
  128. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +2 -0
  129. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +2 -0
  130. metadata +85 -24
  131. data/lib/zakuro/calculation/gengou/internal/counter.rb +0 -129
  132. data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +0 -183
  133. data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +0 -382
  134. data/lib/zakuro/calculation/gengou/scroll.rb +0 -262
  135. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  136. data/lib/zakuro/era/japan/gengou/parser.rb +0 -237
  137. data/lib/zakuro/era/japan/gengou/type.rb +0 -285
  138. data/lib/zakuro/era/japan/gengou/validator.rb +0 -341
  139. data/lib/zakuro/result/data.rb +0 -187
  140. data/lib/zakuro/result/operation.rb +0 -114
  141. data/lib/zakuro/version/context.rb +0 -44
  142. data/lib/zakuro/version/version_class_resolver.rb +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 567799c25255c97ec707d421b465358c1209afeef0d8c2f1c84a9b3bd5e65148
4
- data.tar.gz: bff172488e9ea94a8da83d09fa1dc9bd62a28de871ad0cc41217d20ff5dc2b94
3
+ metadata.gz: fd91623531440c342355fd005938af7cc10d07ae858dfb83d51704c6c1eab92c
4
+ data.tar.gz: 0a1bfca6ded7403960512c9854c5b22e95b761fb1c8d04fd530cb4806c2eaf66
5
5
  SHA512:
6
- metadata.gz: daf11f9f9319d23fbba463571cb8f76184aeb7b6133fcde661bd06773113f37bc9684e8680a848c4998a96ea287f371ca123f878a7bb5dbdfb2ed499c434f8a7
7
- data.tar.gz: 3624066b34b4271961793f58bbad9509b046a3df967df4513de195352237386ccd5848b9b5f72c8838f6efb944fac1129b494001c570aa2cb5a93440d089e173
6
+ metadata.gz: 76d1ad94413f1b0101964e6ac292e8e4074e2441418a1e31ad3f46d01397e5dba54afaf4799f1a45b310cb32bc17dc27bcf0d6a76348486dacb8a45ecf0df7e3
7
+ data.tar.gz: f97b9d72fde20c6bcf991f8136b8c9ee935516c27243f7a46ad60c1c38abe32cecb825a51083f01b605d9f4a00810df7c29be09a6564b2881000dd9ae6713786
data/Makefile CHANGED
@@ -1,2 +1,5 @@
1
1
  binstub:
2
2
  bundle binstubs rspec-core --path exe
3
+
4
+ count:
5
+ find . -type f -name "*.rb" | xargs cat | sed "/^\s*\(#\|\$\)/d" | wc -l
data/README.md CHANGED
@@ -30,7 +30,9 @@ Or install it yourself as:
30
30
 
31
31
  開発途中です。
32
32
 
33
- 下記表で対応済とした暦の1日検索のみ対応しております。
33
+ 1日検索/期間検索に対応しております。
34
+
35
+ 下記表で対応済の暦は使用可能です。
34
36
 
35
37
  |開始日|暦 |計算方法|対応|
36
38
  |:----|:----|:----|:----|
@@ -61,8 +63,7 @@ western_date = Date.new(862, 2, 3)
61
63
  # 初期化時の設定
62
64
  merchant = Zakuro::Merchant.new(condition: { date: western_date })
63
65
  puts merchant.commit.to_json
64
- # => {"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"
65
- 大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"}}}}
66
+ # => {"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"options":{}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"options":{}}}}
66
67
 
67
68
  western_date = Date.new(1685, 2, 3)
68
69
 
@@ -70,7 +71,12 @@ western_date = Date.new(1685, 2, 3)
70
71
  # merchant = Zakuro::Merchant.new
71
72
  merchant.offer(condition: { date: western_date })
72
73
  puts merchant.commit.to_json
73
- # => {"data":{"year":{"first_gengou":{"name":"貞享","number":1},"second_gengou":{"name":"","number":-1},"zodiac_name":"甲子","total_days":354},"month":{"number":12,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"壬辰","remainder":"28-4182","western_date":"1685-01-05"},"odd_solar_terms":[{"index":1,"remainder":"30-890"}],"even_solar_terms":[{"index":2,"remainder":"45-2726"}]},"day":{"number":30,"zodiac_name":"辛酉","remainder":"57-4182","western_date":"1685-02-03"}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞享","number":1},"second_gengou":{"name":"","number":-1},"zodiac_name":"甲子","total_days":354},"month":{"number":12,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"壬辰","remainder":"28-4182","western_date":"1685-01-05"},"odd_solar_terms":[{"index":1,"remainder":"30-890"}],"even_solar_terms":[{"index":2,"remainder":"45-2726"}]},"day":{"number":30,"zodiac_name":"辛酉","remainder":"57-4182","western_date":"1685-02-03"}}}}
74
+ # => {"data":{"year":{"first_gengou":{"name":"貞享","number":1},"second_gengou":{"name":"","number":-1},"zodiac_name":"","total_days":354},"month":{"number":12,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"壬辰","remainder":"28-4182","western_date":"1685-01-05"},"odd_solar_terms":[{"index":1,"remainder":"30-890"}],"even_solar_terms":[{"index":2,"remainder":"45-2726"}]},"day":{"number":30,"zodiac_name":"辛酉","remainder":"57-4182","western_date":"1685-02-03"},"options":{}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞享","number":1},"second_gengou":{"name":"","number":-1},"zodiac_name":"","total_days":354},"month":{"number":12,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"壬辰","remainder":"28-4182","western_date":"1685-01-05"},"odd_solar_terms":[{"index":1,"remainder":"30-890"}],"even_solar_terms":[{"index":2,"remainder":"45-2726"}]},"day":{"number":30,"zodiac_name":"辛酉","remainder":"57-4182","western_date":"1685-02-03"},"options":{}}}}
75
+
76
+ # 期間検索
77
+ merchant = Zakuro::Merchant.new(condition: { range: {start: Date.new(862, 2, 3), last: Date.new(862, 2, 4)}})
78
+ puts merchant.commit.to_json
79
+ # => {"list":[{"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"options":{}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"options":{}}}},{"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":2,"zodiac_name":"辛未","remainder":"7-1282","western_date":"0862-02-04"},"options":{}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":2,"zodiac_name":"辛未","remainder":"7-1282","western_date":"0862-02-04"},"options":{}}}}]}
74
80
  ```
75
81
 
76
82
  # 条件
@@ -80,26 +86,36 @@ puts merchant.commit.to_json
80
86
  | 項目名 | キー名 | hash内キー名 | データ型 | 備考 |
81
87
  |----------------|---------|--------------|----------|--------------------|
82
88
  | 基準日 | date | | Date | 西暦日 |
83
- | | | | String | 和暦日 |
84
- | 範囲(開始日) | range | start | Date | |
85
- | 範囲(終了日) | | last | Date | |
89
+ | | | | String | 和暦日/西暦日 |
90
+ | 範囲(開始日) | range | start | Date | 西暦日 |
91
+ | | | | String | 和暦日/西暦日 |
92
+ | 範囲(終了日) | | last | Date | 西暦日 |
93
+ | | | | String | 和暦日/西暦日 |
86
94
  | 列 | columns | | Array | 取得したい列の列名 |
87
- | オプション | options | | Array | 取得オプション |
95
+ | オプション | options | | Hash<String, Object> | 取得オプション |
88
96
 
89
- 現時点では `date` の西暦日のみ対応中です。
97
+ 現時点では `date` と `range` のみ対応中です。
90
98
 
91
99
  ## オプション
92
100
 
93
101
  | 項目名 | キー名 | データ型 | データ | 備考 |
94
102
  |--------|-----------|----------|--------|------------------------|
95
- | 単位 | unit | String | year | 年単位 |
96
- | | | | month | 月単位 |
97
- | | | | day | 日単位(デフォルト) |
98
- | 没日 | lost_days | TRUE | | 没日あり |
99
- | | | FALSE | | 没日なし(デフォルト) |
103
+ | | version | String | Genka | 元嘉暦 |
104
+ | | | | Gihou | 儀鳳暦 |
105
+ | | | | Daien | 大衍暦 |
106
+ | | | | Senmyou | 宣明暦 |
107
+ | | | | Joukyou | 貞享暦 |
108
+ | | | | Kansei | 寛政暦 |
109
+ | | | | Tenpou | 天保暦 |
110
+ | | | | Gregorio | グレゴリオ暦 |
111
+ | | | | | 指定なし(デフォルト) |
112
+ | 没日 | dropped_days | TRUE | | 没日あり |
113
+ | | | FALSE | | 没日なし(デフォルト) |
100
114
  | 四季 | seasons | TRUE | | 四季あり |
101
115
  | | | FALSE | | 四季なし(デフォルト) |
102
116
 
117
+ 現時点では宣明暦の [没日](./doc/dropped_date.md) のみ試験的に対応しております(結果未検証)。
118
+
103
119
  # 期待値
104
120
  暦算値は『日本暦日原典』、元号の切り替えは『日本史年表 第5版』を範とします。
105
121
 
@@ -119,6 +135,12 @@ puts merchant.commit.to_json
119
135
  | 日付情報 | data | | | Zakuro::Result::Data::SingleDay | - | 運用値(計算値は運用情報内を参照のこと)|
120
136
  | 運用情報 | operation | | | Zakuro::Result::Operation::Bundle | - | - |
121
137
 
138
+ ### Zakuro::Result::Range
139
+
140
+ | 項目名 | キー名 | - | - | データ型 | 参考値 | 備考   |
141
+ |----------|-----------|---|---|---------------------------------------|--------|---------------------------------------|
142
+ | 日リスト | list | | | Array\<Zakuro::Result::Data::Single\> | - | 範囲内の日付情報すべて |
143
+
122
144
  ### Zakuro::Result::SingleDay
123
145
 
124
146
  | 項目名 | キー名 | - | - | データ型 | 参考値 | 備考 |
@@ -151,6 +173,7 @@ puts merchant.commit.to_json
151
173
  | 日の干支 | | zodiac_name | | String | 乙卯 | 日の干支 |
152
174
  | 日の大余小余 | | remainder | | String | 51-2479 | 大余小余 |
153
175
  | 西暦日 | | western_date | | String | 0937-02-14 | 西暦日 |
176
+ | オプション | options | | | Hash<String, Zakuro::Result::Data::Option::AbstractOption>| | オプション値 |
154
177
 
155
178
  ### Zakuro::Result::Operation
156
179
 
@@ -176,10 +199,24 @@ puts merchant.commit.to_json
176
199
  | 月初日の西暦日 | | western_date |   | String | 0937-02-13 | 計算値 |
177
200
  | 原文頁数 | | page |   | Integer | 178 |   |
178
201
  | 原文注釈番号 | | number |   | Integer | 1 |   |
179
- | 注釈 | | annotations |   | Array<Zakuro::Result::Operation::::MonthAnnotation> |   |   |
180
- | 注釈内容 |   | | description | String | 計算は51乙卯であるが, 日本紀略に甲寅朔とある。正月甲寅朔のユリウス暦日は2月13日となる。(元旦日食 をさけるための変更か) |   |
202
+ | 注釈 | | annotations |   | Array\<Zakuro::Result::Operation::MonthAnnotation\> |   |   |
203
+ | 注釈内容 |   | | description | String | 計算は51乙卯であるが, 日本紀略に甲寅朔とある。<br>正月甲寅朔のユリウス暦日は2月13日となる。(元旦日食 をさけるための変更か) |   |
181
204
  | 注釈補記 |   | | note | String | - | 原文訂正 |
182
205
 
206
+ ### Zakuro::Result::Data::Option::AbstractOption
207
+
208
+ #### Zakuro::Result::Data::Option::DroppedDate::Option
209
+
210
+ キー: dropped_date
211
+
212
+ | 項目名 | キー名 | - | - | データ型 | 参考値 | 備考 |
213
+ | -------------------- | ----------- | ---------- | --------- | ------------------------------------------------------ | -------- | ------------------ |
214
+ | オプション値有無 | matched | | | True/False | true | |
215
+ | 演算値 | calculation | | | Zakuro::Result::Data::Option::DroppedDate::Calculation | | |
216
+ | 没余 | | remainder | | String | 59-34155 | |
217
+ | 二十四節気 | | solar_term | | Zakuro::Result::Data::Option::DroppedDate::SolarTerm | | |
218
+ | 二十四節気番号 | | | index | Integer | 6 | |
219
+ | 二十四節気の大余小余 | | | remainder | String | 49-7203 | |
183
220
 
184
221
  # 元号
185
222
 
@@ -194,6 +231,11 @@ puts merchant.commit.to_json
194
231
 
195
232
  [宣明暦](./lib/zakuro/version/senmyou/README.md) のみ記載しております。
196
233
 
234
+ # 例外
235
+
236
+ 条件不正などで例外が発生します。
237
+ 詳細は [例外処理](./doc/error.md) を参照してください。
238
+
197
239
  ## コントリビュート(Contributing)
198
240
 
199
241
  バグ報告/修正はこちらまで。
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.2
@@ -0,0 +1,93 @@
1
+ # 没日
2
+ 没日を端的に説明すると、1太陽年(365.24..日)を360日で表わすために、一定の法則で `存在しない日` として配置された日である
3
+
4
+ 太陽の運行に対応するため、基本的には二十四節気をもとに計算を行う
5
+
6
+ # 期待値
7
+ 「日本暦日便覧」に従う
8
+
9
+ ## 計算
10
+ 「長慶宣明暦算法」に従う
11
+
12
+ 下記は該当箇所の引用と、それに対応する計算を示している
13
+
14
+ ```
15
+ ◯没日ヲ求ルノ術
16
+ 没日ト云ハ毎日の気盈ノ數ツモリテ統法ノ八千四百ニ満タル日ヲ云其モトメヤウノ法ナリ
17
+ ```
18
+
19
+ ```
20
+ 常氣ノ小餘六千五百六十四秒三巳上ハ物之ヲ置テ
21
+ 常氣ハ前ノ等法ニテ求メタル二十四氣トナリ其二十四節氣ノ内イツレニモ小余ノ數六千五百六十四秒三ヨリ以上アラハ没日ヲ求メヨトナリ
22
+ タトヘハ小余ノ數六千五百六十四秒アリテモ秒三ヨリ内ナラハモトムヘラカス秒ノ數ハスクナレトモ小余ノ數多クアラハ求ムヘシ
23
+ 小余ノ一ハ秒ノ八ナレハナリ
24
+ 畢竟ハ小余六千五百六十四秒三アルカ尤モソレヨリ以上アラハ求ムヘシ少シモ以下ナラハ求ムヘカラストナリ
25
+ ```
26
+
27
+ 次のパターンのみ求める
28
+ * 常気の小余 >= 6564.3
29
+
30
+ ```
31
+ 三百六十ヲ以テ之乗シ別ニ秒ヲ置テ四十五ヲ以テ之乗シ小餘ノ之上ニ加フ
32
+ 常氣ノ小余ノ數ニカクルナリ今立春ノ小余八千二百三十六秒七アリ
33
+ 故に没日ヲ求メントテマツ其立春ノ小余八千二百三十六ニ三百六十ヲカクレハ二百九十六萬四千九百六十トナル
34
+ 又別ニ秒七ヲ置テ是ニ四十五ヲカクレハ三百一十五トナル
35
+ 此ヲ右ノ二百九十六萬四千九百六十ニ加フレハ合セテ二百九十六萬五千二百七十五トナル
36
+ 又秒七ヲ八ニワリテ小余ノ次ニ置テ八千二百三十六八分七厘五毛トツテ子テ是ニ三百六十ヲカクレハ二百九十六萬五千二百七十五トナルモ同シ等法ナリ
37
+ ```
38
+
39
+ ある立春の小余: 8236.7
40
+ * A
41
+ * 8236 * 360 = 2964960
42
+ * 7 * 45 = 315
43
+ * 2964960 + 315 = 2965275
44
+ * B
45
+ * 8236 + 7/8 = 8236.875 * 360 = 2965275
46
+
47
+ ```
48
+ 而ソ章歳ノ三百零六萬八千零五十五ヲ以テ直減シ
49
+ 以ハ用ナリ置テト云心ナルヘシ此章歳ノ數三百零六萬八千零五十五ヲ置テコノ内ヲ右ノ二百九十六萬五千二百七十五去テ残テ一十萬零二千七百八十トナルナリ
50
+ 細注ニ或ハ少ヲ以テ多ニ減ストアレトモ是ハアヤマリナルヘシ
51
+ タトヘハ常氣ノ小余八千三百九十九秒七アルトキニ右ノ法ノ如クニシテミレハ三百零二萬三千九百五十五トナル
52
+ コレ章歳ノ數ニ四萬四千一百タラサルナリ
53
+ 然レハ必ラス定テ章歳ノ數ノ内ヲ減スルノ明トシ常氣ノ小余八千三百九十九秒七ヨリ多キクハナキケリ
54
+ ```
55
+ 章歳: 3068055
56
+
57
+ * 3068055 - 2965275 = 102780
58
+ * 負数はない。負数であれば正数にする
59
+
60
+ ```
61
+ 残分ヲ置テ通餘ノ四萬四千一零五十五ヲ以テ之ヲ除シ商ヲ以テ日ト為 常氣ノ之大餘ヲ加フ甲子自之ヲ命シ等外ヲ用フ也
62
+ 残分ト云ハ右ノ章歳ヲ減シタル残リ一十萬零二千七百八十トナリ此數ヲ置テ通余ノ四萬四千一零五十五ニテワレハ商ニ不盡一萬四千六百七十アリ
63
+ サテ此商二ニ常氣立春ノ大余五十六ヲ加レハ五十八トナル
64
+ コレヲ没日ノ大余ノ數トス
65
+ サテ右ノ不盡一萬四千六百七十ヲ没日ノ小余トス
66
+ 其大余ノ數モシ六十ニ満ツルトキハハラヒ去リテ其残リヲ用テサテ前ノ二十四氣ニテ攴干ヲ付タル如ク紀法ノ圖ニテ付ヘシ今大余五十八ハ壬戌ニアタルナリ
67
+ 立春一氣ノ内ニ壬戌ノ日アルヲ没日ノ日トス
68
+ サテ是ハ立春ノ一氣ヲ記セリ
69
+ 二十四氣ノ内イツレニテモ有没日ノ数小余六千五百六十四秒巳上アラハ右ノ如クニシテ求ムヘシ
70
+ ```
71
+
72
+ 通余: 44055
73
+
74
+ * 102780 / 44055 = 2.3329... ≒ 2
75
+ * 102780 % 44055 = 14670
76
+ * 56(立春大余) + 2 = 58
77
+
78
+ 没日: 58-14670
79
+
80
+ ```
81
+ 次ヲ求ルノ術
82
+ ```
83
+
84
+ ```
85
+ 大餘ニ九 小餘ニ二萬八千二百六十
86
+ 二十四氣ノ内ヲ考ヘテイツレニテモ有没日ノ小余六千五百六十四秒三以上アル時ハ右ノ法ノ如ニシテ求ムヘシ
87
+ 又一術アリモトメ得タル没日ノ大余ニ九加エ小余ニ二萬八千二百六十加エテ小余通余ノ四萬四千零五十五ニ満レハ一ニツツメテ其一ヲ大余ニ加ヘ大余六十ニ満レハ去此ノ如ク累加スレハ次々ノ没日ヲ求メ得ルナリ
88
+ 其アル日ハ有没日ノ六千五百六十四秒三以上アル處ノ氣ノ内ニアルトシルヘシ
89
+
90
+ ```
91
+ * 大余 + 9
92
+ * 小余 + 28260
93
+ * 小余 > 44055 の場合は繰り上げ
data/doc/error.md ADDED
@@ -0,0 +1,45 @@
1
+ # 例外処理
2
+
3
+ ## Zakuro::Exception::ZakuroError
4
+
5
+ 例外は `ZakuroError` に集約されます。
6
+
7
+ ```
8
+ merchant = Zakuro::Merchant.new(condition: {})
9
+ merchant.commit
10
+ Traceback (most recent call last):
11
+ 4: from ./bin/console:14:in `<main>'
12
+ 3: from (irb):5
13
+ 2: from /Users/ty/ruby/zakuro/lib/zakuro/merchant.rb:81:in `commit'
14
+ 1: from /Users/ty/ruby/zakuro/lib/zakuro/merchant.rb:132:in `make_uncommitable_error'
15
+ Zakuro::Exception::ZakuroError (an error has occurred:[{"code":"ERROR_0203","message":"検索不可能な日付指定です。"}])
16
+ ```
17
+
18
+ 例外に対応したコードとメッセージを取得できます。
19
+ ```
20
+ merchant = Zakuro::Merchant.new(condition: {})
21
+ begin
22
+ merchant.commit
23
+ rescue Zakuro::Exception::ZakuroError => e
24
+ p e.causes[0].code
25
+ p e.causes[0].message
26
+ end
27
+ => "ERROR_0203"
28
+ => "検索不可能な日付指定です。"
29
+ ```
30
+
31
+ ## エラー種別
32
+
33
+ `Zakuro::Exception::Case::Pattern` の通りです。
34
+
35
+ |コード|メッセージ|引数長|
36
+ |:----|:----|:----|
37
+ |ERROR_0001|内部エラーです。|0|
38
+ |ERROR_0101|日付の型は文字列/日付です。指定型:%s|1|
39
+ |ERROR_0102|範囲の型はhashです。指定型:%s|1|
40
+ |ERROR_0103|オプションの型はhashです。指定型:%s|1|
41
+ |ERROR_0104|列の型は配列です。指定型:%s|1|
42
+ |ERROR_0105|条件の型は配列です。指定型:%s|1|
43
+ |ERROR_0201|一日検索の日付指定が誤っています。|0|
44
+ |ERROR_0202|範囲検索の日付指定が誤っています。|0|
45
+ |ERROR_0203|検索不可能な日付指定です。|0|
@@ -39,25 +39,25 @@ table.each do |row|
39
39
  'diffs' => {
40
40
  'month' => {
41
41
  'number' => {
42
- 'calc' => month_str_to_number(row['月(計)']),
43
- 'actual' => month_str_to_number(row['月(実)'])
42
+ 'src' => month_str_to_number(row['月(計)']),
43
+ 'dest' => month_str_to_number(row['月(実)'])
44
44
  },
45
45
  'leaped' => {
46
- 'calc' => month_str_to_leaped(row['月(計)']),
47
- 'actual' => month_str_to_leaped(row['月(実)'])
46
+ 'src' => month_str_to_leaped(row['月(計)']),
47
+ 'dest' => month_str_to_leaped(row['月(実)'])
48
48
  },
49
49
  'days' => {
50
- 'calc' => row['月大小(計)'],
51
- 'actual' => row['月大小(実)']
50
+ 'src' => row['月大小(計)'],
51
+ 'dest' => row['月大小(実)']
52
52
  }
53
53
  },
54
54
  'solar_term' => {
55
- 'calc' => {
55
+ 'src' => {
56
56
  'index' => row['中気番号(計)'],
57
57
  'to' => row['中気移動先'],
58
58
  'zodiac_name' => row['中気(計)']
59
59
  },
60
- 'actual' => {
60
+ 'dest' => {
61
61
  'index' => row['中気番号(実)'],
62
62
  'from' => row['中気移動元'],
63
63
  'zodiac_name' => row['中気(実)']
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../era/western/calendar'
4
+ require_relative '../cycle/abstract_remainder'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Base
12
+ #
13
+ # Day 日
14
+ #
15
+ class Day
16
+ # @return [Integer] 不正日
17
+ INVALID_NUMBER = -1
18
+
19
+ # @return [Integer] 日
20
+ attr_reader :number
21
+ # @return [Western::Calendar] 西暦日
22
+ attr_reader :western_date
23
+ # @return [Cycle::AbstractRemainder] 和暦日
24
+ attr_reader :remainder
25
+
26
+ #
27
+ # 初期化
28
+ #
29
+ # @param [Integer] number 日
30
+ # @param [Western::Calendar] western_date 西暦日
31
+ # @param [Cycle::AbstractRemainder] 和暦日
32
+ #
33
+ def initialize(number: INVALID_NUMBER, western_date: Western::Calendar.new,
34
+ remainder: Cycle::AbstractRemainder.new)
35
+ @number = number
36
+ @western_date = western_date
37
+ @remainder = remainder
38
+ end
39
+
40
+ #
41
+ # 不正か
42
+ #
43
+ # @return [True] 不正
44
+ # @return [False] 不正なし
45
+ #
46
+ def invalid?
47
+ number == INVALID_NUMBER
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -15,7 +15,7 @@ module Zakuro
15
15
  # @return [Western::Calendar] 開始日
16
16
  attr_reader :start_date
17
17
  # @return [Western::Calendar] 終了日
18
- attr_reader :end_date
18
+ attr_reader :last_date
19
19
  # @return [Array<LinearGengou>] 1行目元号
20
20
  attr_reader :first_line
21
21
  # @return [Array<LinearGengou>] 2行目元号
@@ -25,14 +25,14 @@ module Zakuro
25
25
  # 初期化
26
26
  #
27
27
  # @param [Western::Calendar] start_date 開始日
28
- # @param [Western::Calendar] end_date 終了日
28
+ # @param [Western::Calendar] last_date 終了日
29
29
  # @param [Array<LinearGengou>] first_line 1行目元号
30
30
  # @param [Array<LinearGengou>] second_line 2行目元号
31
31
  #
32
- def initialize(start_date: Western::Calendar.new, end_date: Western::Calendar.new,
32
+ def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
33
33
  first_line: [], second_line: [])
34
34
  @start_date = start_date
35
- @end_date = end_date
35
+ @last_date = last_date
36
36
  @first_line = first_line
37
37
  @second_line = second_line
38
38
  end
@@ -67,6 +67,52 @@ module Zakuro
67
67
  LinearGengou.new
68
68
  end
69
69
 
70
+ #
71
+ # 元号を取得する
72
+ #
73
+ # @param [String] name 元号名
74
+ #
75
+ # @return [LinearGengou] 元号
76
+ #
77
+ def match_by_name(name:)
78
+ result = match_first_line_by_name(name: name)
79
+ return result unless result.invalid?
80
+
81
+ result = match_second_line_by_name(name: name)
82
+
83
+ result
84
+ end
85
+
86
+ #
87
+ # 1行目元号を取得する
88
+ #
89
+ # @param [String] name 元号名
90
+ #
91
+ # @return [LinearGengou] 1行目元号
92
+ #
93
+ def match_first_line_by_name(name:)
94
+ @first_line.each do |line|
95
+ return line.clone if line.name == name
96
+ end
97
+
98
+ LinearGengou.new
99
+ end
100
+
101
+ #
102
+ # 2行目元号を取得する
103
+ #
104
+ # @param [String] name 元号名
105
+ #
106
+ # @return [LinearGengou] 2行目元号
107
+ #
108
+ def match_second_line_by_name(name:)
109
+ @second_line.each do |line|
110
+ return line.clone if line.name == name
111
+ end
112
+
113
+ LinearGengou.new
114
+ end
115
+
70
116
  #
71
117
  # 不正か
72
118
  #
@@ -17,7 +17,7 @@ module Zakuro
17
17
  # @return [Western::Calendar] 開始日
18
18
  attr_reader :start_date
19
19
  # @return [Western::Calendar] 終了日
20
- attr_reader :end_date
20
+ attr_reader :last_date
21
21
  # @return [String] 元号名
22
22
  attr_reader :name
23
23
  # @return [Integer] 年
@@ -27,14 +27,14 @@ module Zakuro
27
27
  # 初期化
28
28
  #
29
29
  # @param [Western::Calendar] start_date 開始日
30
- # @param [Western::Calendar] end_date 終了日
30
+ # @param [Western::Calendar] last_date 終了日
31
31
  # @param [String] name 元号名
32
32
  # @param [Integer] 元号年
33
33
  #
34
- def initialize(start_date: Western::Calendar.new, end_date: Western::Calendar.new,
34
+ def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
35
35
  name: '', year: INVALID_YEAR)
36
36
  @start_date = start_date
37
- @end_date = end_date
37
+ @last_date = last_date
38
38
  @name = name
39
39
  @year = year
40
40
  end
@@ -62,11 +62,11 @@ module Zakuro
62
62
 
63
63
  return false if @start_date.invalid?
64
64
 
65
- return false if @end_date.invalid?
65
+ return false if @last_date.invalid?
66
66
 
67
67
  return false if date < @start_date
68
68
 
69
- return false if date > @end_date
69
+ return false if date > @last_date
70
70
 
71
71
  true
72
72
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative './year'
4
4
 
5
- require_relative '../../version/context'
5
+ require_relative '../../context/context'
6
6
 
7
7
  # :nodoc:
8
8
  module Zakuro
@@ -17,11 +17,11 @@ module Zakuro
17
17
  #
18
18
  # 初期化
19
19
  #
20
- # @param [Context] context 暦コンテキスト
20
+ # @param [Context::Context] context 暦コンテキスト
21
21
  # @param [Array<OperatedMonth>] months 年内の全ての月
22
22
  # @param [Integer] total_days 年の日数
23
23
  #
24
- def initialize(context: Context.new, months: [], total_days: 0)
24
+ def initialize(context: Context::Context.new, months: [], total_days: 0)
25
25
  super(context: context, months: months, total_days: total_days)
26
26
  end
27
27
 
@@ -4,7 +4,7 @@ require_relative '../cycle/zodiac'
4
4
 
5
5
  require_relative '../../era/western/calendar'
6
6
 
7
- require_relative '../../version/context'
7
+ require_relative '../../context/context'
8
8
 
9
9
  # :nodoc:
10
10
  module Zakuro
@@ -16,7 +16,7 @@ module Zakuro
16
16
  # Year 年
17
17
  #
18
18
  class Year
19
- # @return [Context] 暦コンテキスト
19
+ # @return [Context::Context] 暦コンテキスト
20
20
  attr_reader :context
21
21
  # @return [Array<Month>] 年内の全ての月
22
22
  attr_reader :months
@@ -26,11 +26,11 @@ module Zakuro
26
26
  #
27
27
  # 初期化
28
28
  #
29
- # @param [Context] context 暦コンテキスト
29
+ # @param [Context::Context] context 暦コンテキスト
30
30
  # @param [Array<Month>] months 年内の全ての月
31
31
  # @param [Integer] total_days 年の日数
32
32
  #
33
- def initialize(context: Context.new, months: [], total_days: 0)
33
+ def initialize(context: Context::Context.new, months: [], total_days: 0)
34
34
  @context = context
35
35
  @months = months
36
36
  @total_days = total_days
@@ -43,16 +43,16 @@ module Zakuro
43
43
  # 初期化
44
44
  #
45
45
  # @param [Integer] base_day 1大余に必要な小余(暦によって基数が異なる)
46
- # @param [Integer] base_mitune 1小余に必要な秒(暦によって基数が異なる)
46
+ # @param [Integer] base_minute 1小余に必要な秒(暦によって基数が異なる)
47
47
  # @param [Integer] day 大余("日"に相当)
48
48
  # @param [Integer] minute 小余("分"に相当)
49
49
  # @param [Integer] second 秒
50
50
  # @param [Integer] total 繰り上げなしの小余
51
51
  #
52
- def initialize(base_day: -1, base_mitune: -1, day: -1, minute: -1, second: -1, total: -1)
52
+ def initialize(base_day: -1, base_minute: -1, day: -1, minute: -1, second: -1, total: -1)
53
53
  @base_limit = LIMIT
54
54
  @base_day = base_day
55
- @base_minute = base_mitune
55
+ @base_minute = base_minute
56
56
  @limited = true
57
57
 
58
58
  set(day: day, minute: minute, second: second, total: total)
@@ -113,6 +113,8 @@ module Zakuro
113
113
  # @return [True] 無効
114
114
  # @return [False] 有効
115
115
  #
116
+ # @raise [ArgumentError] 引数エラー
117
+ #
116
118
  def invalid?(param: self)
117
119
  raise ArgumentError, 'unmatch parameter type' unless param.is_a?(AbstractRemainder)
118
120