four-pillars 0.1.3 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/four-pillars.rb +183 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05b1b6919825e6f97cd615abbf7ca7d446d031bc15524c7e42a8f17c211bf905
|
4
|
+
data.tar.gz: 2c4f1c1450a8af51b2fd0aaa65dd41559b77de7a8d7fb64d2cc8793109ddf748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bce4f1bcec1539c8d75a5a9e1009464fc07f64389f9649becbb69da6e6ea70f3d8fac0ce5e6bbc52dcf150daaf98f68317b4a9c1e509ec9c379fefa2a7ec6d42
|
7
|
+
data.tar.gz: 07333c1ea69b35433eebd12e83b2ddebf0327b866a6c9d765330b3fc585662d4603e639416d3e2222aea0b7cceda9f7aeb9dcb382a3324781e08bec3449c897e
|
data/lib/four-pillars.rb
CHANGED
@@ -14,9 +14,9 @@ class FourPillarsLogic
|
|
14
14
|
["庚丁壬","癸丙","壬甲","甲庚","甲丙癸","丙甲癸","甲丁","壬甲","甲庚","丙甲辛"],
|
15
15
|
["癸庚丁","癸辛","壬庚","甲庚","甲癸丙","癸丙辛","壬戊丙","壬癸甲","壬庚辛","辛壬"],
|
16
16
|
["癸丁庚","癸丙","壬庚","壬庚","壬甲丙","癸丙辛","壬癸庚","壬癸乙","癸庚辛","辛壬"],
|
17
|
-
["癸","癸丙甲","壬庚","甲壬","
|
17
|
+
["癸","癸丙甲","壬庚","甲壬","癸丙甲","癸丙","丁甲","壬甲庚","辛甲","辛壬癸"],
|
18
18
|
["庚丁壬","丙癸","壬戊","甲庚丙","丙癸甲","丙癸","丁甲","壬甲","戊丁","丁甲"],
|
19
|
-
["
|
19
|
+
["庚丁丙癸","丙癸","壬","甲庚丙","丙癸","丙癸","丁甲丙","壬","甲庚","辛丙"],
|
20
20
|
["癸庚丁甲","癸辛甲","甲壬","甲庚","甲丙癸","甲丙","甲壬","壬甲","甲丙戊","辛甲癸"],
|
21
21
|
["癸丁丙戊","丙戊","甲戊庚","甲庚","甲丙","丙甲戊","丁甲丙","壬丙","戊丙庚","辛戊"]]
|
22
22
|
|
@@ -84,7 +84,34 @@ class FourPillarsLogic
|
|
84
84
|
end
|
85
85
|
SETSUIRI_HASH, SETSUIRI_LIST = load_setsuiri
|
86
86
|
|
87
|
-
#
|
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
|
+
# 生年月日時間, 性別(大運の向きに使用)
|
88
115
|
attr_reader :birth_dt,:gender
|
89
116
|
|
90
117
|
def initialize(birth_dt,gender)
|
@@ -115,6 +142,12 @@ class FourPillarsLogic
|
|
115
142
|
(Date.new(y,m,1) - 1).day
|
116
143
|
end
|
117
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
|
+
|
118
151
|
# 前月の節入日
|
119
152
|
def setsuiri_of_previous_month
|
120
153
|
y,m,d,h,i = @birth_dt
|
@@ -127,6 +160,18 @@ class FourPillarsLogic
|
|
127
160
|
SETSUIRI_HASH[y*100+m] || [0,0]
|
128
161
|
end
|
129
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
|
+
|
130
175
|
# 生年月に対する節入日時を知っているか?
|
131
176
|
# このメソッドがfalseを返す場合、干支、蔵干が仮の節入日で計算されています。
|
132
177
|
def know_setsuiri?
|
@@ -213,20 +258,9 @@ class FourPillarsLogic
|
|
213
258
|
|
214
259
|
# 通変星(nil,月,年)
|
215
260
|
def tsuhensei
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
else # 陰
|
220
|
-
jikkan = JIKKAN_IN
|
221
|
-
end
|
222
|
-
j = jikkan.index(kanshi[0][0])
|
223
|
-
j_month = jikkan.index(kanshi[1][0])
|
224
|
-
j_year = jikkan.index(kanshi[2][0])
|
225
|
-
t_month = j_month - j
|
226
|
-
t_month += 10 if t_month < 0
|
227
|
-
t_year = j_year - j
|
228
|
-
t_year += 10 if t_year < 0
|
229
|
-
[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]
|
230
264
|
end
|
231
265
|
|
232
266
|
# 蔵干通変星
|
@@ -252,20 +286,10 @@ class FourPillarsLogic
|
|
252
286
|
|
253
287
|
# 十二運星
|
254
288
|
def jyuniunsei
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
jyunishi = JYUNISHI_IN
|
260
|
-
end
|
261
|
-
offset = [1,7,10,10,10,10,7,1,4,4][j] # 十二運表より求めたオフセット
|
262
|
-
j_day = jyunishi.index(kanshi[0][1])
|
263
|
-
j_month = jyunishi.index(kanshi[1][1])
|
264
|
-
j_year = jyunishi.index(kanshi[2][1])
|
265
|
-
u_day = (j_day + offset) % 12
|
266
|
-
u_month = (j_month + offset) % 12
|
267
|
-
u_year = (j_year + offset) % 12
|
268
|
-
[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]
|
269
293
|
end
|
270
294
|
|
271
295
|
def jyuniunsei_energy
|
@@ -318,9 +342,10 @@ class FourPillarsLogic
|
|
318
342
|
# 日柱の十干と月柱の十二支
|
319
343
|
x = JIKKAN.index(kanshi[0][0])
|
320
344
|
y = JYUNISHI.index(kanshi[1][1])
|
321
|
-
SHUGOSHIN[y][x]
|
345
|
+
SHUGOSHIN[y][x].split("")
|
322
346
|
end
|
323
347
|
|
348
|
+
# 宿命中殺
|
324
349
|
def shukumei
|
325
350
|
s = []
|
326
351
|
t = kuubou # 天中殺 0:上段, 1:下段
|
@@ -340,6 +365,132 @@ class FourPillarsLogic
|
|
340
365
|
s += ["日座中殺"] if f
|
341
366
|
return s
|
342
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 = 59 if k < 0
|
490
|
+
k = 0 if k > 59
|
491
|
+
end
|
492
|
+
return rows
|
493
|
+
end
|
343
494
|
end
|
344
495
|
|
345
496
|
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.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yosei Ito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-24 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
|