Class: When::CalendarNote

Inherits:
TM::ReferenceSystem show all
Defined in:
lib/when_exe/calendarnote.rb,
lib/when_exe/region/indian.rb,
lib/when_exe/region/martian.rb,
lib/when_exe/region/japanese_notes.rb,
lib/when_exe/region/ephemeric_notes.rb,
lib/when_exe.rb

Overview

Ephemeris を用いる暦注

Defined Under Namespace

Modules: LabelAccess, Notes Classes: BalineseNote, Christian, DarianWeek, Enumerator, EphemericNote, HinduNote, HinduNoteDetailed, JapaneseLuniSolarNote, JapaneseNote, JapaneseSolarNote, LunarPhases, LuniSolarPositions, NoteElement, RomanNote, ShireWeek, SolarTerms, WorldWeek

Constant Summary collapse

DefaultNotes =
[['_m:CalendarTerms::Month'], ['CommonResidue::Week']]
JulianDayNotes =
[['CommonResidue::Week', 'CommonResidue::干支']]
BahaiNotes =
[['Bahai::YearName'], ['_m:BahaiTerms::Month'], ['CommonResidue::Week']]
JavaneseNotes =
[['Javanese::Windu'], ['_m:CalendarTerms::Month'],
['Javanese::Pasaran', 'Javanese::Paringkelan', 'Javanese::Week', 'Javanese::Wuku']]
ChineseNotes =
[['CommonResidue::干支'], ['_m:CalendarTerms::Month'], ['CommonResidue::Week', 'CommonResidue::干支']]
TibetanNotes =
[['Tibetan::干支'], ['_m:CalendarTerms::Month'], ['CommonResidue::Week']]
YiNotes =
[['Yi::YearName'], ['_m:CalendarTerms::Month'], ['CommonResidue::Week']]
MayanNotes =
[{},['Mayan#{?Epoch=Epoch}::Trecena', 'Mayan#{?Epoch=Epoch}::Tzolk\'in',
'Mayan#{?Epoch=Epoch}::Lords_of_the_Night', 'Mayan#{?Epoch=Epoch}::Haab\'']]

Constants included from Parts::Resource

Parts::Resource::LabelProperty

Instance Attribute Summary collapse

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 TM::ReferenceSystem

#domain, #name

Methods included from Parts::Resource

#[], #^, _decode, _encode, _extract_prefix, _instance, _instantiate, _parse, _path_with_prefix, _replace_tags, _setup_, _setup_info, _simplify_path, base_uri, #each, #hierarchy, #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

#eventString

Note:

イベント名の後ろに数字が使われている場合、数字部分以降はイベントメソッドの引数になります。 SolarTermsクラスで ‘term180’ は、太陽黄経180度のイベントすなわち秋分を意味します。

デフォルトイベント名

Returns:



211
212
213
# File 'lib/when_exe/calendarnote.rb', line 211

def event
  @event
end

Instance Method Details

#copy(event) ⇒ When::CalendarNote

デフォルトイベントの指定

Parameters:

  • event (String)

    指定値を@eventとした新しいオブジェクトを作る

Returns:



220
221
222
223
224
# File 'lib/when_exe/calendarnote.rb', line 220

def copy(event)
  c = self.clone
  c.event = event
  c
end

#dayWhen::BasicTypes::M17n



# File 'lib/when_exe/calendarnote.rb', line 389

#duration(event = @event) ⇒ When::TM::PeriodDuration

典型的なイベントの発生間隔

Parameters:

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

Returns:



232
233
234
235
# File 'lib/when_exe/calendarnote.rb', line 232

def duration(event=@event)
  void, event, parameter = event.split(/^([^\d]+)/)
  send((event+'_delta').downcase.to_sym, parameter)
end

#enum_for(range, options = {}) ⇒ Enumerator #enum_for(first, direction = :forward, options = {}) ⇒ Enumerator Also known as: to_enum

Enumeratorの生成

Overloads:

  • #enum_for(range, options = {}) ⇒ Enumerator

    Parameters:

    Options Hash (options):

    • :event (String)

      イベント名(デフォルトは@event)

    • :count_limit (Integer)

      繰り返し回数(デフォルトは指定なし)

  • #enum_for(first, direction = :forward, options = {}) ⇒ Enumerator

    Parameters:

    • first (When::TM::TemporalPosition)

      始点

    • direction (Symbol) (defaults to: :forward)

      (optionsで渡してもよい)

      :forward

      昇順(デフォルト)

      :reverse

      降順

    • options (Hash) (defaults to: {})

      以下の通り

    Options Hash (options):

    • :event (String)

      イベント名(デフォルトは@event)

    • :count_limit (Integer)

      繰り返し回数(デフォルトは指定なし)

Returns:



271
272
273
274
275
276
277
278
# File 'lib/when_exe/calendarnote.rb', line 271

def enum_for(*args)
  params  = args.dup
  options = params[-1].kind_of?(Hash) ? params.pop.dup : {}
  options[:event] ||= @event
  self.class::Enumerator.new(*(params[0].kind_of?(Range) ?
    [self, params[0],                        options] :
    [self, params[0], params[1] || :forward, options]))
end

#include?(date, event = @event) ⇒ Boolean

指定の日時が指定イベントに該当するか?

Parameters:

Returns:

  • (Boolean)
    true - 該当する
    false - 該当しない


246
247
248
# File 'lib/when_exe/calendarnote.rb', line 246

def include?(date, event=@event)
  enum_for(date, :forward, event.downcase).next.include?(date)
end

#monthWhen::BasicTypes::M17n



# File 'lib/when_exe/calendarnote.rb', line 385

#note?(date, options = {}) ⇒ Boolean

暦注の一致 or 不一致

Parameters:

  • date (When::TM::TemporalPosition)

    暦注を確認する日時

  • date (When::TM::TemporalPosition 以外)

    When::TM::TemporalPosition に変換して使用する

  • options (String) (defaults to: {})

    { :notes => String } または { :value => String } という Hash の指定と等価 (指定の notes が存在する場合は前者、しない場合は後者)

  • options (Integer) (defaults to: {})

    { :indices => Integer } という Hash の指定と等価

  • options (Hash) (defaults to: {})

    下記のとおり

Options Hash (options):

  • :value (暦注の値)

    確認する暦注の値(または正規表現)

  • その他 (それぞれ)

    #notes を参照

Returns:

  • (Boolean)
    true - 暦注が一致
    false - 暦注が不一致


367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/when_exe/calendarnote.rb', line 367

def note?(date, options={})
  options = _find_note(options)    if options.kind_of?(String)
  pattern = options.delete(:value) if options.kind_of?(Hash)
  result  = notes(date, options)
  result.flatten!
  result.delete_if {|hash| hash.empty?}
  return false unless result.size > 0
  return true unless pattern
  result.each do |hash|
    return true if Notes.verify(pattern, hash[:value])
  end
  return false
end

#notes(date, options = {}) ⇒ Array<Array<Hash>>

Note:

CalendarNoteオブジェクト生成時に _normalize メソッド内で @prime 変数を設定しておけば、 本メソッドの :prime オプションで参照される。(BalineseNote#_normalize等参照)

Note:

暦注のビットアドレスは、暦注サブクラスのNoteObjects定数の中の定義順序による。 When::CalendarNote クラスの場合 new の引数とした暦注要素リストの定義順序による。 ビットアドレスの値が 1 の暦注が計算対象となる。

Note:

戻り値の :value が When::TM::TemporalPosition の場合、その日時オブジェクトの events に暦注名の入った 暦注に該当する日付である。(例) Christian クラス で easter を計算した場合、当該年の復活祭の日付オブジェクトが返る。

Note:

暦注サブクラスの場合、暦注要素が増えたり、:note の暦注要素の型が変わったりすることがある。

暦注の計算

Parameters:

  • date (When::TM::TemporalPosition)

    暦注を計算する日時

  • date (When::TM::TemporalPosition 以外)

    When::TM::TemporalPosition に変換して使用する

  • options (String) (defaults to: {})

    { :notes => String } という Hash の指定と等価

  • options (Integer) (defaults to: {})

    { :indices => Integer} という Hash の指定と等価

  • options (Hash) (defaults to: {})

    下記のとおり

Options Hash (options):

  • :indices (Integer)

    Integerで指定した暦座標の暦注を計算

    When::DAY ( 0) - 日
    When::MONTH(-1) - 月
    When::YEAR (-2) - 年
  • :indices (Array<Integer>)

    Integerで指定したすべて暦座標の暦注を計算

  • :indices (nil)

    すべての暦座標の暦注を計算(デフォルト)

  • :notes (String)

    計算する暦注名(日の暦注)

  • :notes (Integer)

    計算する暦注のビット配列(日の暦注)

  • :notes (Array<Array<String>>)

    計算する暦注名の Array の Array

  • :notes (Array<Integer>)

    計算する暦注のビット配列の Array

  • :notes (:all)

    すべての暦注を計算

  • :notes (:prime, nil)

    @prime に登録した暦注を計算、@prime未登録なら :all と同じ(デフォルト)

  • :persistence (Hash)

    ユリウス通日=>暦注計算結果を保持する永続オブジェクト

  • :conditions (Hash)

    暦注計算の条件

    :location => 暦注計算の基準となる場所(String or When::Coordinates::Spatial)
    その他のキー => 個々の暦注クラスごとにその他のキーを使用できる
  • その他のキー (Hash)

    date を When::TM::TemporalPosition に変換するために使用する see TM::TemporalPosition._instance

Returns:

  • (Array<Array<Hash>>)

    暦注計算結果(When::CalendarNote::Notesモジュールをextendしている)

    :note => 暦注要素 (When::Coordinates::Residue, String, When::BasicTypes::M17n)
    :value => 暦注の値 (When::Coordinates::Residue, String, When::BasicTypes::M17n, When::TM::TemporalPosition)


326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/when_exe/calendarnote.rb', line 326

def notes(date, options={})
  dates, indices, notes, persistence, conditions, options = _parse_note(date, options)
  retrieved = Notes.retrieve(persistence, date.to_i)
  return retrieved unless retrieved == false
  Notes.register(indices.map {|i|
    next [] unless i <= date.precision
    _note_values(dates, notes[i-1], _all_keys[i-1], _elements[i-1]) do |dates, focused_notes, notes_hash|
      focused_notes.each do |note|
        unless notes_hash[note]
          void, event, *parameter = note.split(/^([^\d]+)/)
          method = event.downcase
          parameter << conditions unless conditions.empty?
          notes_hash[note] = 
            if respond_to?(method)
              send(method, dates, *parameter)
            else
              _elements[i-1][note].send(When::Coordinates::PRECISION_NAME[i].downcase, dates)
            end
        end
      end
      notes_hash
    end
  }, persistence, date.to_i)
end

#yearWhen::BasicTypes::M17n



# File 'lib/when_exe/calendarnote.rb', line 381