Class: Zakuro::Calculation::Option::DroppedDate::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/zakuro/calculation/option/dropped_date/location.rb

Overview

Location 没日位置

Constant Summary collapse

IDEAL_YEAR =

Returns 理想上の年日数.

Returns:

  • (Integer)

    理想上の年日数

360

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, solar_term:) ⇒ Location

初期化

Parameters:



38
39
40
41
42
43
44
45
46
# File 'lib/zakuro/calculation/option/dropped_date/location.rb', line 38

def initialize(context:, solar_term:)
  parameter = context.resolver.dropped_date_parameter.new
  @context = context
  @valid = parameter.valid
  @limit = parameter.limit
  @year = parameter.year
  @remainder_class = parameter.remainder_class
  @solar_term = solar_term
end

Instance Attribute Details

#contextContext::Context (readonly)

Returns 暦コンテキスト.

Returns:



19
20
21
# File 'lib/zakuro/calculation/option/dropped_date/location.rb', line 19

def context
  @context
end

#limitCycle::AbstractRemainder (readonly)

Returns 「有没之気」判定.

Returns:



24
25
26
# File 'lib/zakuro/calculation/option/dropped_date/location.rb', line 24

def limit
  @limit
end

#remainder_classClass (readonly)

Returns 没余クラス.

Returns:

  • (Class)

    没余クラス



30
31
32
# File 'lib/zakuro/calculation/option/dropped_date/location.rb', line 30

def remainder_class
  @remainder_class
end

#solar_termCycle::AbstractSolarTerm (readonly)

Returns 二十四節気.

Returns:



28
29
30
# File 'lib/zakuro/calculation/option/dropped_date/location.rb', line 28

def solar_term
  @solar_term
end

#validTrue, False (readonly)

Returns:

  • (True)

    有効

  • (False)

    無効



22
23
24
# File 'lib/zakuro/calculation/option/dropped_date/location.rb', line 22

def valid
  @valid
end

#yearInteger (readonly)

Returns 年.

Returns:

  • (Integer)



26
27
28
# File 'lib/zakuro/calculation/option/dropped_date/location.rb', line 26

def year
  @year
end

Instance Method Details

#exist?True, False

没日が存在するか?

Returns:

  • (True)

    存在あり

  • (False)

    存在なし



64
65
66
67
68
69
70
71
72
73
# File 'lib/zakuro/calculation/option/dropped_date/location.rb', line 64

def exist?
  remainder = solar_term_remainder

  return false if remainder.invalid?

  minute_later = remainder.class.new(
    day: 0, minute: remainder.minute, second: remainder.second
  )
  minute_later >= limit
end

#getCycle::AbstractRemainder

「没余」を返す

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/zakuro/calculation/option/dropped_date/location.rb', line 80

def get
  # 1. 二十四節気の大余小余を取り出す
  remainder = solar_term_remainder

  # p "remainder: #{remainder.format(form: '%d-%d.%.5f')}"

  # 2. 小余360、秒45(360/8)で乗算する
  total = multiple_ideal_year(remainder: remainder)
  # p "total: #{total}"
  # 3. 上記2と章歳(3068055)の差を求める
  diff = (year - total).abs
  # p "year: #{year}"
  # p "diff: #{diff}"
  # 4. 上記3を通余で徐算する
  result = remainder_class.new(total: diff)
  # p "result: #{result.format(form: '%d-%d.%.5f')}"
  # 5. 上記4の商と上記1の大余が没日大余、余りが小余(没余)
  day = remainder_class.new(day: remainder.day, minute: 0, second: 0)

  day.add(result)
end

#invalid?True, False

不正か

Returns:

  • (True)

    不正

  • (False)

    不正なし



54
55
56
# File 'lib/zakuro/calculation/option/dropped_date/location.rb', line 54

def invalid?
  !@valid
end