four-pillars 0.1.0 → 0.1.5

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 +158 -1
  3. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55ae7bbac7b03fc10d511fe675b204d6d7371fc145aa6a39039f86943a16c067
4
- data.tar.gz: fc97e06b6f4e8395f032289b743005be4538ad713e8d9e5778801697c616caad
3
+ metadata.gz: d6eefa515e7dfb952f9bdbe39d8b13c98f7877fe2c199de4f5194a64d39d1a67
4
+ data.tar.gz: 2f7d0f8273fb44a68281e921586fc235f54b8e3ea967d4158ba9a2a0f7638ec9
5
5
  SHA512:
6
- metadata.gz: 2ca6f6e070e6bf25211f7035604b4181cbb14b9537b97617b9055467728dc8988cefdda103b571dcef83309e95fe554441ac5ae1f329a7711364b8552c5d61fa
7
- data.tar.gz: 8fbdae40818e228a58a4c65ca70e426612c926dafa92cd9528fc3c4eb92753bc7b2817da3163bd26c6c64dcc37f6f85664287f0a224aecf4ec1988a982e96738
6
+ metadata.gz: 2d642d0f265a32094ac7c52463cb87262ef3b24618a76aeeff267fb58c734a5a7bd1e54c16968db943e4f8a3617c3521b6ed6117ba6fb2ab23e4b935f5caaee3
7
+ data.tar.gz: 79f754b9f7f38ba34da0038caca8b4b19c70e5b1bf92756ed543d3bffd55a7bf7cfd377caff3d31a87529a91cf502d86e65059dc47581178fb7204aa03e0d04a
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,7 @@ class FourPillarsLogic
72
84
  end
73
85
  SETSUIRI_HASH, SETSUIRI_LIST = load_setsuiri
74
86
 
75
- # 生年月日時間, 性別(鑑定には使用しない)
87
+ # 生年月日時間, 性別(大運の向きに使用)
76
88
  attr_reader :birth_dt,:gender
77
89
 
78
90
  def initialize(birth_dt,gender)
@@ -103,6 +115,12 @@ class FourPillarsLogic
103
115
  (Date.new(y,m,1) - 1).day
104
116
  end
105
117
 
118
+ # 今月の日数
119
+ def days_of_current_month
120
+ y,m,d,h,i = @birth_dt
121
+ Date.new(y,m,1).next_month.prev_day.day
122
+ end
123
+
106
124
  # 前月の節入日
107
125
  def setsuiri_of_previous_month
108
126
  y,m,d,h,i = @birth_dt
@@ -115,6 +133,18 @@ class FourPillarsLogic
115
133
  SETSUIRI_HASH[y*100+m] || [0,0]
116
134
  end
117
135
 
136
+ # 翌月の節入日
137
+ def setsuiri_of_next_month
138
+ y,m,d,h,i = @birth_dt
139
+ if m == 12
140
+ y += 1
141
+ m = 1
142
+ else
143
+ m += 1
144
+ end
145
+ SETSUIRI_HASH[y*100+m] || [0,0]
146
+ end
147
+
118
148
  # 生年月に対する節入日時を知っているか?
119
149
  # このメソッドがfalseを返す場合、干支、蔵干が仮の節入日で計算されています。
120
150
  def know_setsuiri?
@@ -300,6 +330,133 @@ class FourPillarsLogic
300
330
  end
301
331
  return arr
302
332
  end
333
+
334
+ # 守護神
335
+ def shugoshin
336
+ # 日柱の十干と月柱の十二支
337
+ x = JIKKAN.index(kanshi[0][0])
338
+ y = JYUNISHI.index(kanshi[1][1])
339
+ SHUGOSHIN[y][x].split("")
340
+ end
341
+
342
+ # 宿命中殺
343
+ def shukumei
344
+ s = []
345
+ t = kuubou # 天中殺 0:上段, 1:下段
346
+ k = kanshi.map {|v| v[1] } # 日,月,年柱の干支
347
+ if t[0].include? k[2]
348
+ s += ["生年中殺"]
349
+ end
350
+ if t[0].include? k[1]
351
+ s += ["生月中殺"]
352
+ end
353
+ if t[1].include? k[0]
354
+ s += ["生日中殺"]
355
+ end
356
+ f = false
357
+ f = true if kanshi_as_number.include? 11 #甲戌
358
+ f = true if kanshi_as_number.include? 12 #乙亥
359
+ s += ["日座中殺"] if f
360
+ return s
361
+ end
362
+
363
+ def equivalent_kanshi(only_jikkan=false)
364
+ if only_jikkan
365
+ k = kanshi.map {|v| v[0] } # 日,月,年柱の十干
366
+ else
367
+ k = kanshi
368
+ end
369
+ if k[0] == k[1] && k[1] == k[2]
370
+ return [[0,1],[0,2],[1,2]]
371
+ elsif k[0] == k[1]
372
+ return [[0,1]]
373
+ elsif k[0] == k[2]
374
+ return [[0,2]]
375
+ elsif k[1] == k[2]
376
+ return [[1,2]]
377
+ else
378
+ return []
379
+ end
380
+ end
381
+
382
+ def on_distance?(j1,j2,d=6)
383
+ i = JYUNISHI.index(j1)
384
+ return j2 == JYUNISHI[(i+d) % 12]
385
+ end
386
+
387
+ # 律音
388
+ def ricchin
389
+ # 干支(十干・十二支)が同じ
390
+ equivalent_kanshi(false)
391
+ end
392
+
393
+ # 納音
394
+ def nacchin
395
+ # 十干が同じで十二支が 沖 の関係にある
396
+ v = []
397
+ eq = equivalent_kanshi(true)
398
+ eq.each do |e|
399
+ k0 = kanshi[e[0]][1]
400
+ k1 = kanshi[e[1]][1]
401
+ v += [e] if on_distance?(k0,k1,6)
402
+ end
403
+ return v
404
+ end
405
+
406
+ # 宿命大半会
407
+ def shukumei_daihankai
408
+ # 十干が同じで十二支が三合会局の関係にある
409
+ v = []
410
+ eq = equivalent_kanshi(true)
411
+ eq.each do |e|
412
+ k0 = kanshi[e[0]][1]
413
+ k1 = kanshi[e[1]][1]
414
+ v += [e] if on_distance?(k0,k1,4)
415
+ end
416
+ eq.each do |e|
417
+ k0 = kanshi[e[0]][1]
418
+ k1 = kanshi[e[1]][1]
419
+ v += [e] if on_distance?(k0,k1,8)
420
+ end
421
+ return v
422
+ end
423
+
424
+ # 大運 [順行 or 逆行, year] or [nil,nil](if gender is not male nor female)
425
+ def taiun
426
+ return [nil,nil] unless ['m','f'].include? @gender
427
+ k = gogyo_jikkan[2][0]
428
+ t = @birth_dt[3] * 60 + @birth_dt[4] # 生まれた時間
429
+ if (@gender == 'm' && k == "+") || (@gender == 'f' && k == '-')
430
+ order = "順行"
431
+ d = setsuiri[0] - birth_dt[2]
432
+ if d > 0 # A 生まれた日が節入り前の場合 (節入り日―誕生日+1)÷3
433
+ year = ((d + 1) / 3.0).round
434
+ elsif d == 0 # 節入り日
435
+ #〈順行〉節入時間「前」=1年 「後」=10年
436
+ if t <= setsuiri[1]
437
+ year = 1
438
+ else
439
+ year = 10
440
+ end
441
+ else # B 生まれた日が節入り後の場合 (誕生月の日数―誕生日+1+翌月の節入り日)÷3
442
+ s = days_of_current_month - birth_dt[2] + 1 + setsuiri_of_next_month[0]
443
+ year = (s / 3.0).round
444
+ end
445
+ else
446
+ order = "逆行"
447
+ if setsuiri?
448
+ #〈逆行〉節入時間「前」=10年 「後」=1年
449
+ if t < setsuiri[1]
450
+ year = 10
451
+ else
452
+ year = 1
453
+ end
454
+ else
455
+ year = (zokan_number / 3.0).round
456
+ end
457
+ end
458
+ return [order,year]
459
+ end
303
460
  end
304
461
 
305
462
  if __FILE__ == $0
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: four-pillars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
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-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Tell your meishiki from your birthday and time.
13
+ description: A class which tells fortune by Four Pillar astrology(四柱推命).
14
14
  email: y-itou@lumber-mill.co.jp
15
15
  executables: []
16
16
  extensions: []
@@ -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
- summary: Fortune telling
43
+ summary: Four Pillar astrology
44
44
  test_files: []