Class: When::CalendarTypes::CalendarNote::EphemericNote

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

Overview

天体暦の暦注

Constant Summary collapse

NoteObjects =
[When::BasicTypes::M17n, [
  "namespace:[en=http://en.wikipedia.org/wiki/, ja=http://ja.wikipedia.org/wiki/]",
  "locale:[=en:, ja=ja:, alias=ja:]",
  "names:[Ephemeric]",

  # 年の暦注 ----------------------------
  [When::BasicTypes::M17n,
    "names:[year]"
  ],

  # 月の暦注 ----------------------------
  [When::BasicTypes::M17n,
    "names:[month]",
    [When::BasicTypes::M17n,
      "names:[Month]"
    ]
  ],

  # 日の暦注 ----------------------------
  [When::BasicTypes::M17n,
    "names:[day]",
      "[Sunrise,   日の出          ]", # 日の出
      "[Sunset,    日の入り        ]", # 日の入り
      [When::Coordinates::Residue,
        "label:[Moon_Age=, 正午月齢=ja:%%<月齢>]",
        "divisor:60",
        "format:[%s(%4.1f)]"
      ],
      "[Moonrise,  月の出          ]", # 月の出
      "[Moonset=,  月の入り        ]", # 月の入り
      [When::BasicTypes::M17n,
        "names:[Tide, 潮汐]",            # 満潮干潮日時
        "[High_Tide=en:Tide, 満潮=ja:%%<潮汐>]",
        "[Low_Tide=en:Tide,  干潮=ja:%%<潮汐>]"
      ]
  ]
]]

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

Attributes inherited from When::CalendarTypes::CalendarNote

#event

Attributes inherited from TM::ReferenceSystem

#domain_of_validity, #position

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 Method Details

#moon_age(date, options = {}) ⇒ Numeric

正午月齢

Parameters:

Returns:

  • (Numeric)

    正午における朔からの経過日数



240
241
242
243
244
# File 'lib/when_exe/region/ephemeric_notes.rb', line 240

def moon_age(date, options={})
  @phase ||= When.CalendarNote('LunarPhases')
  noon = date.floor(When::DAY,When::SYSTEM) + 0.5
  @root['Moon_Age'][noon.to_f - @phase.term(noon, [-30.0,30.0]).to_f]
end

#moonrise(date, options = {}) ⇒ When::TM::TemporalPosition

月の出

Parameters:

Returns:



254
255
256
257
258
259
260
# File 'lib/when_exe/region/ephemeric_notes.rb', line 254

def moonrise(date, options={})
  event = formula(date.location.iri).moonrise(date)
  event.events = [@root['Moonrise']]
  event
rescue
  nil
end

#moonset(date, options = {}) ⇒ When::TM::TemporalPosition

月の入り

Parameters:

Returns:



270
271
272
273
274
275
276
# File 'lib/when_exe/region/ephemeric_notes.rb', line 270

def moonset(date, options={})
  event = formula(date.location.iri).moonset(date)
  event.events = [@root['Moonset']]
  event
rescue
  nil
end

#sunrise(date, options = {}) ⇒ When::TM::TemporalPosition

日の出

Parameters:

Returns:



208
209
210
211
212
213
214
# File 'lib/when_exe/region/ephemeric_notes.rb', line 208

def sunrise(date, options={})
  event = formula(date.location.iri).sunrise(date)
  event.events = [@root['Sunrise']]
  event
rescue
  nil
end

#sunset(date, options = {}) ⇒ When::TM::TemporalPosition

日の入り

Parameters:

Returns:



224
225
226
227
228
229
230
# File 'lib/when_exe/region/ephemeric_notes.rb', line 224

def sunset(date, options={})
  event = formula(date.location.iri).sunset(date)
  event.events = [@root['Sunset']]
  event
rescue
  nil
end

#tide(date, options = {}) ⇒ Array<Array<Integer, When::TM::TemporalPosotion>>

干潮・満潮の日時

Parameters:

Options Hash (options):

  • tide (String)

    潮汐計算方式 ‘Horizontal’ - 地平高度基準, ‘Equatorial’ - 子午線通過基準(デフォルト)

Returns:

  • (Array<Array<Integer, When::TM::TemporalPosotion>>)

    干潮・満潮の日時の Array

    Integer

    +1:満潮, -1:干潮

    When::TM::TemporalPosotion

    干潮・満潮の日時



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/when_exe/region/ephemeric_notes.rb', line 291

def tide(date, options={})
  return nil unless @interval
  @target  ||= When.Resource('_ep:Moon')
  events     = @root['Tide']
  form       = formula(date.location.iri)
  type       = options[:tide] =~ /^horizon/i ? nil : 0

  now        = +date
  high_tides = []
  5.times do |i|
    high_tide = form.day_event(now + i - 2, type, @target) + @interval
    high_tides << high_tide if high_tides.size == 0 || high_tide > high_tides[-1] + 0.5
  end
  tides = []

  (high_tides.size-1).times do |i|
    tides << [0, high_tides[i]]
    tides << [1, 0.75*high_tides[i] + 0.25*high_tides[i+1]]
    tides << [0, 0.50*high_tides[i] + 0.50*high_tides[i+1]]
    tides << [1, 0.25*high_tides[i] + 0.75*high_tides[i+1]]
  end
  tides << [0, high_tides[-1]]

  today = +date.floor(When::DAY)...+date.ceil(When::DAY)
  seed  = date._attr
  seed[:clock] ||= When::TM::Clock.local_time
  tides.select {|x| today.include?(x[1])}.map {|x|
    d = form._to_seed_type(x[1], seed)
    d.events = [events[x[0]]]
    d
  }
rescue
  nil
end