Class: When::CalendarNote::LuniSolarPositions

Inherits:
When::CalendarNote show all
Defined in:
lib/when_exe/ephemeris/notes.rb

Overview

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

Direct Known Subclasses

LunarPhases, SolarTerms

Constant Summary

Constants inherited from When::CalendarNote

Bahai, CalendarDepend, Chinese, CommonWithRokuyo, CommonWithSovietFiveDay, CommonWithSovietSixDay, Default, Javanese, JulianDay, Mayan, Tibetan, Yis

Constants included from Parts::Resource

Parts::Resource::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty

Instance Attribute Summary collapse

Attributes inherited from When::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::CalendarNote

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

Methods inherited from TM::ReferenceSystem

#domain, #name

Methods included from Parts::Resource

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

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:



39
40
41
# File 'lib/when_exe/ephemeris/notes.rb', line 39

def delta
  @delta
end

#denNumeric (readonly)

座標の分母

Returns:



27
28
29
# File 'lib/when_exe/ephemeris/notes.rb', line 27

def den
  @den
end

#formulaWhen::Ephemeris::Formula (readonly)

計算アルゴリズム



33
34
35
# File 'lib/when_exe/ephemeris/notes.rb', line 33

def formula
  @formula
end

#marginNumeric (readonly)

没滅計算用の補正

Returns:



45
46
47
# File 'lib/when_exe/ephemeris/notes.rb', line 45

def margin
  @margin
end

#numNumeric (readonly)

座標の分子

Returns:



21
22
23
# File 'lib/when_exe/ephemeris/notes.rb', line 21

def num
  @num
end

Instance Method Details

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

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

Parameters:

  • parameter (String) (defaults to: nil)

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

Returns:



116
117
118
119
120
# File 'lib/when_exe/ephemeris/notes.rb', line 116

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

#event_eval(date, parameter = @event, precision = nil) ⇒ When::TM::CalDate

イベントの日時

Parameters:

  • date (When::TM::TemporalPosition)

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

  • parameter (Array<Numeric>) (defaults to: @event)

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

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

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

  • parameter (String) (defaults to: @event)

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

  • precision (Integer) (defaults to: nil)

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

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/when_exe/ephemeris/notes.rb', line 61

def event_eval(date, parameter=@event, precision=nil)
  date         = When.when?(date) unless date.kind_of?(When::TimeValue)
  precision  ||= date.precision
  num, den     = parameter.kind_of?(String) ? (parameter[/\d.*\z/]||'').split(/\//, 2) : parameter
  num = (num || @num).to_f
  den = (den || @den).to_f
  date      = date.floor(precision) if precision < date.precision
  options   = date._attr
  is_date_and_time = options.key?(:clock) || precision > When::DAY
  options[:precision] = precision
  options[:clock]   ||= date.frame.time_basis || When::TM::Clock.local_time
  sdn       = _the_date(date, num, den)
  time      = When::TM::JulianDate._d_to_t(sdn)
  if @formula.is_dynamical
    time    = date.time_standard.from_dynamical_time(time)
    time   += options[:clock].universal_time(sdn.round) if options[:clock].kind_of?(When::CalendarTypes::LocalTime)
  end
  event = date.frame.jul_trans(When::TM::JulianDate.universal_time(time), options)
  is_date_and_time ? event : event.to_cal_date
end

#event_time(date, event_name, event) ⇒ Object

イベント日付(時刻付)



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/when_exe/ephemeris/notes.rb', line 126

def event_time(date, event_name, event)
  etime = term(date - When.Duration('P3D'), event, When::SYSTEM)
  if formula.respond_to?(:year_length) && formula.denominator && formula.denominator < 100000
    fraction  =  etime.clk_time.local_time
    fraction +=  When::TM::Duration::DAY * (etime.to_i - date.to_i)
    fraction  = (fraction  / When::TM::Duration::DAY * formula.denominator * 1000 + 0.5).floor / 1000.0
    fraction  =  fraction.to_i if fraction == fraction.to_i
    event_name + "(#{fraction}/#{formula.denominator})"
  else
    etime.events = [event_name]
    etime
  end
end

#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 なら滅)



102
103
104
105
106
# File 'lib/when_exe/ephemeris/notes.rb', line 102

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