Class: When::CalendarTypes::CalendarNote::LuniSolarPositions

Inherits:
When::CalendarTypes::CalendarNote show all
Defined in:
lib/when_exe/region/ephemeric_notes.rb

Overview

太陽と月の位置によるイベント

Direct Known Subclasses

LunarPhases, SolarTerms

Constant Summary

Constants inherited from When::CalendarTypes::CalendarNote

BahaiNotes, ChineseNotes, DefaultNotes, JavaneseNotes, JulianDayNotes, MayanNotes, TibetanNotes, YiNotes

Constants included from Parts::Resource

Parts::Resource::LabelProperty

Instance Attribute Summary collapse

Attributes inherited from When::CalendarTypes::CalendarNote

#event

Attributes inherited from TM::ReferenceSystem

#domain_of_validity

Attributes inherited from BasicTypes::Object

#label

Attributes included from Parts::Resource

#_pool, #child, #keys, #locale, #namespace

Instance Method Summary collapse

Methods inherited from When::CalendarTypes::CalendarNote

#copy, #day, #duration, #enum_for, #include?, #month, #note?, #notes, #year

Methods inherited from TM::ReferenceSystem

#domain, #name

Methods included from Parts::Resource

#[], #^, _decode, _encode, _extract_prefix, _instance, _parse, _path_with_prefix, _replace_tags, _setup_, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #next, #parent, #prev, #registered?

Methods included from Parts::Resource::Pool

#[], #[]=, #_pool, #_setup_, #pool_keys

Methods included from Parts::Resource::Synchronize

#synchronize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class When::Parts::Resource

Instance Attribute Details

#deltaNumeric (readonly)

enumerator の周期

Returns:


41
42
43
# File 'lib/when_exe/region/ephemeric_notes.rb', line 41

def delta
  @delta
end

#denNumeric (readonly)

座標の分母

Returns:


29
30
31
# File 'lib/when_exe/region/ephemeric_notes.rb', line 29

def den
  @den
end

#formulaWhen::Ephemeris::Formula (readonly)

計算アルゴリズム


35
36
37
# File 'lib/when_exe/region/ephemeric_notes.rb', line 35

def formula
  @formula
end

#marginNumeric (readonly)

没滅計算用の補正

Returns:


47
48
49
# File 'lib/when_exe/region/ephemeric_notes.rb', line 47

def margin
  @margin
end

#numNumeric (readonly)

座標の分子

Returns:


23
24
25
# File 'lib/when_exe/region/ephemeric_notes.rb', line 23

def num
  @num
end

Instance Method Details

#position(date, delta = 0) ⇒ Array<Integer>

日付に対応する座標

Parameters:

Returns:

  • (Array<Integer>)

    Array< Integer, 0 or 1 or 2 >

    Integer

    対応する座標

    0 or 1 or 2

    座標の進み(0 なら 没, 2 なら滅)


90
91
92
93
94
# File 'lib/when_exe/region/ephemeric_notes.rb', line 90

def position(date, delta=0)
  date   = date.floor
  p0, p1 = [date, date.succ].map {|d| (30.0 * @formula.time_to_cn(d) - @margin + delta).floor}
  [p1 % @den, p1 - p0]
end

#term(date, parameter = nil, precision = date.precision) ⇒ When::TM::CalDate

イベントの日時

Parameters:

  • date (When::TM::TemporalPosition)

    イベントを探す基準とする日時

  • parameter (Array<Numeric>) (defaults to: nil)

    座標の分子と分母( num, den)

    num 座標の分子 (デフォルト @num)

    den 座標の分母 (デフォルト @den)

  • parameter (String) (defaults to: nil)

    座標の分子と分母(“#{ num }/#{ den }” の形式)

  • precision (Integer) (defaults to: date.precision)

    取得したい時間位置の分解能(デフォルト date の分解能)

Returns:


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/when_exe/region/ephemeric_notes.rb', line 63

def term(date, parameter=nil, precision=date.precision)
  precision = nil if precision == When::SYSTEM
  num, den  = parameter.kind_of?(String) ? parameter.split(/\//, 2) : parameter
  num = (num || @num).to_f
  den = (den || @den).to_f
  date      = date.floor(precision) if precision
  options   = date._attr
  quot, mod = (@formula.time_to_cn(date)*30.0).divmod(den)
  cycle     = quot * den + num
  cycle    += den if mod > (num % den)
  time      = When::TM::JulianDate._d_to_t(@formula.cn_to_time(cycle/30.0))
  time      = date.time_standard.from_dynamical_time(time) if @formula.is_dynamical
  date      = date.frame.jul_trans(When::TM::JulianDate.universal_time(time), options)
  precision ? date.floor(precision) : date
end

#term_delta(parameter = nil) ⇒ When::TM::IntervalLength

イベントの標準的な間隔を返す

Parameters:

  • parameter (String) (defaults to: nil)

    座標の分子と分母(“#{ num }/#{ den }” の形式)

Returns:


102
103
104
105
106
# File 'lib/when_exe/region/ephemeric_notes.rb', line 102

def term_delta(parameter=nil)
  return @delta unless parameter
  num, den = parameter.split(/\//, 2)
  When::TM::IntervalLength.new([(den || @den).to_f-1,1].max, 'day')
end