four-pillars 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/four-pillars.rb +219 -29
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ede123ece7bef5cfc20dd130450ade38b0adc19d1d7f42109951deea8b3406c1
4
- data.tar.gz: 58e71701de20c570898d7fb5a4ab65d91811b07207dc3b726af079e80c2ea108
3
+ metadata.gz: 8cae18ae8469d23ee4f7114902d3bc722621bf2d6b09392968ad8854d4f8676a
4
+ data.tar.gz: 30ff71bb5aa3e3cdf255fbef1e1d99e76656673cdf49e5a3b2bb8222ebbab576
5
5
  SHA512:
6
- metadata.gz: 9e4271a9a2e761587b744852be1866248c49d206a00edb512109e5cc9137d3b6da1e716487e80fd53aca234737a71e6e3a059a9bda332d75216101ca5989282b
7
- data.tar.gz: d04f78654e6853d323484937553253adcc21d7ffbc27d2f2e30e7b3b11fb38dfa3db14d0a64ad08e5f91eabe678c135fd270fcbd6d72680e3a73d3482839fa65
6
+ metadata.gz: 6a83c3eb9bf581259d968063279c1b9c1904f1eb59ab78df5144fbdbda0364d362afd05073287af5b653dbdf021dd8eab021d3a5c5b980f9af8a6edc8078d810
7
+ data.tar.gz: 251f178751f795ce3d171e3e61cbcaa36155caa4596649478fb373a7ed1ec5183e6dc32ed4c366c36e51bd0ac39099031c11b5c1e602d3d0adb2510d2e418e4a
data/lib/four-pillars.rb CHANGED
@@ -7,6 +7,18 @@ class FourPillarsLogic
7
7
  JYUNIUNSEI = ["長生","沐浴","冠帯","建禄","帝旺","衰","病","死","墓","絶","胎","養"]
8
8
  GOGYO = ["木","火","土","金","水"]
9
9
  KUUBOU = ["戌亥","申酉","午未","辰巳","寅卯","子丑"]
10
+ SHUGOSHIN = [["丁庚丙","丙戊","壬戊","甲庚","丙甲","丙甲戊","丁甲戊","丙壬","戊丙","丙辛"],
11
+ ["丁庚甲","丙甲","甲壬","甲庚","丙甲","丙甲","丙甲丁","丙壬甲","丙甲","丙壬戊"],
12
+ ["丙癸","丙癸","壬庚","甲庚","丙甲癸","丙戊甲","丙甲戊","己壬庚","庚丙戊","辛丙"],
13
+ ["庚丁丙","丙癸","壬庚己","庚甲","丙甲癸","甲丙癸","丁甲庚","壬甲","戊辛","庚辛"],
14
+ ["庚丁壬","癸丙","壬甲","甲庚","甲丙癸","丙甲癸","甲丁","壬甲","甲庚","丙甲辛"],
15
+ ["癸庚丁","癸辛","壬庚","甲庚","甲癸丙","癸丙辛","壬戊丙","壬癸甲","壬庚辛","辛壬"],
16
+ ["癸丁庚","癸丙","壬庚","壬庚","壬甲丙","癸丙辛","壬癸庚","壬癸乙","癸庚辛","辛壬"],
17
+ ["癸","癸丙甲","壬庚","甲壬","丙癸甲","癸丙","丁甲","壬甲庚","辛甲","辛壬癸"],
18
+ ["庚丁壬","丙癸","壬戊","甲庚丙","丙癸甲","丙癸","丁甲","壬甲","戊丁","丁甲"],
19
+ ["癸庚丁甲","丙癸","壬","甲庚丙","丙癸","丙癸","丁甲丙","壬","甲庚","辛丙"],
20
+ ["癸庚丁甲","癸辛甲","甲壬","甲庚","甲丙癸","甲丙","甲壬","壬甲","甲丙戊","辛甲癸"],
21
+ ["癸丁丙戊","丙戊","甲戊庚","甲庚","甲丙","丙甲戊","丁甲丙","壬丙","戊丙庚","辛戊"]]
10
22
 
11
23
  # 60干支表
12
24
  def self.kanshi_array
@@ -72,7 +84,34 @@ class FourPillarsLogic
72
84
  end
73
85
  SETSUIRI_HASH, SETSUIRI_LIST = load_setsuiri
74
86
 
75
- # 生年月日時間, 性別(鑑定には使用しない)
87
+ # 通変星
88
+ def self.tsuhensei(j_day,j_src) # 日柱の十干、月柱または年柱の十干
89
+ j = JIKKAN.index(j_day)
90
+ if j % 2 == 0 # 陽
91
+ jikkan = JIKKAN
92
+ else # 陰
93
+ jikkan = JIKKAN_IN
94
+ end
95
+ t = jikkan.index(j_src) - jikkan.index(j_day)
96
+ t += 10 if t < 0
97
+ TSUHENSEI[t]
98
+ end
99
+
100
+ def self.jyuniunsei(j_day,j_src) # 日柱の十干, 十二支
101
+ j = JIKKAN.index(j_day)
102
+ if j % 2 == 0 # 陽
103
+ jyunishi = JYUNISHI
104
+ else # 陰
105
+ jyunishi = JYUNISHI_IN
106
+ end
107
+ offset = [1,7,10,10,10,10,7,1,4,4][j] # 十二運表より求めたオフセット
108
+ ji = jyunishi.index(j_src)
109
+ JYUNIUNSEI[(ji + offset) % 12]
110
+ end
111
+
112
+ # TODO エネルギー
113
+
114
+ # 生年月日時間, 性別(大運の向きに使用)
76
115
  attr_reader :birth_dt,:gender
77
116
 
78
117
  def initialize(birth_dt,gender)
@@ -103,6 +142,12 @@ class FourPillarsLogic
103
142
  (Date.new(y,m,1) - 1).day
104
143
  end
105
144
 
145
+ # 今月の日数
146
+ def days_of_current_month
147
+ y,m,d,h,i = @birth_dt
148
+ Date.new(y,m,1).next_month.prev_day.day
149
+ end
150
+
106
151
  # 前月の節入日
107
152
  def setsuiri_of_previous_month
108
153
  y,m,d,h,i = @birth_dt
@@ -115,6 +160,18 @@ class FourPillarsLogic
115
160
  SETSUIRI_HASH[y*100+m] || [0,0]
116
161
  end
117
162
 
163
+ # 翌月の節入日
164
+ def setsuiri_of_next_month
165
+ y,m,d,h,i = @birth_dt
166
+ if m == 12
167
+ y += 1
168
+ m = 1
169
+ else
170
+ m += 1
171
+ end
172
+ SETSUIRI_HASH[y*100+m] || [0,0]
173
+ end
174
+
118
175
  # 生年月に対する節入日時を知っているか?
119
176
  # このメソッドがfalseを返す場合、干支、蔵干が仮の節入日で計算されています。
120
177
  def know_setsuiri?
@@ -201,20 +258,9 @@ class FourPillarsLogic
201
258
 
202
259
  # 通変星(nil,月,年)
203
260
  def tsuhensei
204
- j = JIKKAN.index(kanshi[0][0])
205
- if j % 2 == 0 # 陽
206
- jikkan = JIKKAN
207
- else # 陰
208
- jikkan = JIKKAN_IN
209
- end
210
- j = jikkan.index(kanshi[0][0])
211
- j_month = jikkan.index(kanshi[1][0])
212
- j_year = jikkan.index(kanshi[2][0])
213
- t_month = j_month - j
214
- t_month += 10 if t_month < 0
215
- t_year = j_year - j
216
- t_year += 10 if t_year < 0
217
- [nil,TSUHENSEI[t_month],TSUHENSEI[t_year]]
261
+ m = FourPillarsLogic::tsuhensei(kanshi[0][0],kanshi[1][0])
262
+ y = FourPillarsLogic::tsuhensei(kanshi[0][0],kanshi[2][0])
263
+ [nil,m,y]
218
264
  end
219
265
 
220
266
  # 蔵干通変星
@@ -240,20 +286,10 @@ class FourPillarsLogic
240
286
 
241
287
  # 十二運星
242
288
  def jyuniunsei
243
- j = JIKKAN.index(kanshi[0][0])
244
- if j % 2 == 0 # 陽
245
- jyunishi = JYUNISHI
246
- else # 陰
247
- jyunishi = JYUNISHI_IN
248
- end
249
- offset = [1,7,10,10,10,10,7,1,4,4][j] # 十二運表より求めたオフセット
250
- j_day = jyunishi.index(kanshi[0][1])
251
- j_month = jyunishi.index(kanshi[1][1])
252
- j_year = jyunishi.index(kanshi[2][1])
253
- u_day = (j_day + offset) % 12
254
- u_month = (j_month + offset) % 12
255
- u_year = (j_year + offset) % 12
256
- [JYUNIUNSEI[u_day],JYUNIUNSEI[u_month],JYUNIUNSEI[u_year]]
289
+ d = FourPillarsLogic::jyuniunsei(kanshi[0][0],kanshi[0][1])
290
+ m = FourPillarsLogic::jyuniunsei(kanshi[0][0],kanshi[1][1])
291
+ y = FourPillarsLogic::jyuniunsei(kanshi[0][0],kanshi[2][1])
292
+ [d,m,y]
257
293
  end
258
294
 
259
295
  def jyuniunsei_energy
@@ -300,6 +336,160 @@ class FourPillarsLogic
300
336
  end
301
337
  return arr
302
338
  end
339
+
340
+ # 守護神
341
+ def shugoshin
342
+ # 日柱の十干と月柱の十二支
343
+ x = JIKKAN.index(kanshi[0][0])
344
+ y = JYUNISHI.index(kanshi[1][1])
345
+ SHUGOSHIN[y][x].split("")
346
+ end
347
+
348
+ # 宿命中殺
349
+ def shukumei
350
+ s = []
351
+ t = kuubou # 天中殺 0:上段, 1:下段
352
+ k = kanshi.map {|v| v[1] } # 日,月,年柱の干支
353
+ if t[0].include? k[2]
354
+ s += ["生年中殺"]
355
+ end
356
+ if t[0].include? k[1]
357
+ s += ["生月中殺"]
358
+ end
359
+ if t[1].include? k[0]
360
+ s += ["生日中殺"]
361
+ end
362
+ f = false
363
+ f = true if kanshi_as_number.include? 11 #甲戌
364
+ f = true if kanshi_as_number.include? 12 #乙亥
365
+ s += ["日座中殺"] if f
366
+ return s
367
+ end
368
+
369
+ def equivalent_kanshi(only_jikkan=false)
370
+ if only_jikkan
371
+ k = kanshi.map {|v| v[0] } # 日,月,年柱の十干
372
+ else
373
+ k = kanshi
374
+ end
375
+ if k[0] == k[1] && k[1] == k[2]
376
+ return [[0,1],[0,2],[1,2]]
377
+ elsif k[0] == k[1]
378
+ return [[0,1]]
379
+ elsif k[0] == k[2]
380
+ return [[0,2]]
381
+ elsif k[1] == k[2]
382
+ return [[1,2]]
383
+ else
384
+ return []
385
+ end
386
+ end
387
+
388
+ def on_distance?(j1,j2,d=6)
389
+ i = JYUNISHI.index(j1)
390
+ return j2 == JYUNISHI[(i+d) % 12]
391
+ end
392
+
393
+ # 律音
394
+ def ricchin
395
+ # 干支(十干・十二支)が同じ
396
+ equivalent_kanshi(false)
397
+ end
398
+
399
+ # 納音
400
+ def nacchin
401
+ # 十干が同じで十二支が 沖 の関係にある
402
+ v = []
403
+ eq = equivalent_kanshi(true)
404
+ eq.each do |e|
405
+ k0 = kanshi[e[0]][1]
406
+ k1 = kanshi[e[1]][1]
407
+ v += [e] if on_distance?(k0,k1,6)
408
+ end
409
+ return v
410
+ end
411
+
412
+ # 宿命大半会
413
+ def shukumei_daihankai
414
+ # 十干が同じで十二支が三合会局の関係にある
415
+ v = []
416
+ eq = equivalent_kanshi(true)
417
+ eq.each do |e|
418
+ k0 = kanshi[e[0]][1]
419
+ k1 = kanshi[e[1]][1]
420
+ v += [e] if on_distance?(k0,k1,4)
421
+ end
422
+ eq.each do |e|
423
+ k0 = kanshi[e[0]][1]
424
+ k1 = kanshi[e[1]][1]
425
+ v += [e] if on_distance?(k0,k1,8)
426
+ end
427
+ return v
428
+ end
429
+
430
+ # 大運 [順行 or 逆行, year] or [nil,nil](if gender is not male nor female)
431
+ def taiun
432
+ return [nil,nil] unless ['m','f'].include? @gender
433
+ k = gogyo_jikkan[2][0]
434
+ t = @birth_dt[3] * 60 + @birth_dt[4] # 生まれた時間
435
+ if (@gender == 'm' && k == "+") || (@gender == 'f' && k == '-')
436
+ order = "順行"
437
+ d = setsuiri[0] - birth_dt[2]
438
+ if d > 0 # A 生まれた日が節入り前の場合 (節入り日―誕生日+1)÷3
439
+ year = ((d + 1) / 3.0).round
440
+ elsif d == 0 # 節入り日
441
+ #〈順行〉節入時間「前」=1年 「後」=10年
442
+ if t <= setsuiri[1]
443
+ year = 1
444
+ else
445
+ year = 10
446
+ end
447
+ else # B 生まれた日が節入り後の場合 (誕生月の日数―誕生日+1+翌月の節入り日)÷3
448
+ s = days_of_current_month - birth_dt[2] + 1 + setsuiri_of_next_month[0]
449
+ year = (s / 3.0).round
450
+ end
451
+ else
452
+ order = "逆行"
453
+ if setsuiri?
454
+ #〈逆行〉節入時間「前」=10年 「後」=1年
455
+ if t < setsuiri[1]
456
+ year = 10
457
+ else
458
+ year = 1
459
+ end
460
+ else
461
+ year = (zokan_number / 3.0).round
462
+ end
463
+ end
464
+ return [order,year]
465
+ end
466
+
467
+ def taiun_table
468
+ order,year = taiun
469
+ return [] if order.nil?
470
+ d = order == '順行' ? 1 : -1
471
+ j_day = kanshi[0][0] # 日柱の十干
472
+ k = kanshi_as_number[1] - 1 # 月柱の干支番号
473
+ rows = []
474
+ # [0,1,"癸亥","偏印","死",2]
475
+ y1, y2 = 0, year
476
+ 8.times do |i|
477
+ k_month = KANSHI_ARRAY[k] # 月柱の干支
478
+ t = FourPillarsLogic::tsuhensei(j_day,k_month[0])
479
+ j = FourPillarsLogic::jyuniunsei(j_day,k_month[1])
480
+ je = JYUNIUNSEI_ENERGY[j]
481
+ rows += [[y1,y2,k_month,t,j,je]]
482
+ if y1 == 0
483
+ y1 = year
484
+ else
485
+ y1 += 10
486
+ end
487
+ y2 += 10
488
+ k += d
489
+ k = 0 if k < 0 || 59 < k
490
+ end
491
+ return rows
492
+ end
303
493
  end
304
494
 
305
495
  if __FILE__ == $0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: four-pillars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yosei Ito
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-30 00:00:00.000000000 Z
11
+ date: 2021-06-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A class which tells fortune by Four Pillar astrology(四柱推命).
14
14
  email: y-itou@lumber-mill.co.jp
@@ -22,7 +22,7 @@ homepage: https://github.com/lumbermill/four-pillars
22
22
  licenses:
23
23
  - MIT
24
24
  metadata: {}
25
- post_install_message:
25
+ post_install_message:
26
26
  rdoc_options: []
27
27
  require_paths:
28
28
  - lib
@@ -37,8 +37,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
39
  requirements: []
40
- rubygems_version: 3.0.3
41
- signing_key:
40
+ rubygems_version: 3.2.15
41
+ signing_key:
42
42
  specification_version: 4
43
43
  summary: Four Pillar astrology
44
44
  test_files: []