Class: When::CalendarTypes::CalendarNote

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

Overview

暦注 - Calendar Note

Defined Under Namespace

Modules: LabelAccess 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'], []]
JulianDayNotes =
[['CommonResidue::Week', 'CommonResidue::干支']]
BahaiNotes =
[['Bahai::YearName'], ['_m:BahaiTerms::Month'], []]
JavaneseNotes =
[['Javanese::Windu'], ['_m:CalendarTerms::Month'],
['Javanese::Pasaran', 'Javanese::Paringkelan', 'Javanese::Week', 'Javanese::Wuku']]
ChineseNotes =
[['CommonResidue::干支'], ['_m:CalendarTerms::Month'], ['CommonResidue::干支']]
TibetanNotes =
[['Tibetan::干支'], ['_m:CalendarTerms::Month'], []]
YiNotes =
[['Yi::YearName'], ['_m:CalendarTerms::Month'], []]
MayanNotes =
[{'0B'=>{'Base'=>'?Epoch=0D'}, '2B'=>{'Base'=>'?Epoch=2D'}},
['Mayan#{Base:}::Trecena', 'Mayan#{Base:}::Tzolk\'in', 'Mayan#{Base:}::Lords_of_the_Night', 'Mayan#{Base:}::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, _parse, _path_with_prefix, _replace_tags, _setup_, #each, #hierarchy, #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

#eventString

Note:

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

デフォルトイベント名

Returns:



1152
1153
1154
# File 'lib/when_exe/calendartypes.rb', line 1152

def event
  @event
end

Instance Method Details

#copy(event) ⇒ When::CalendarTypes::CalendarNote

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

Parameters:

  • event (String)

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

Returns:



1161
1162
1163
1164
1165
# File 'lib/when_exe/calendartypes.rb', line 1161

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

#dayWhen::BasicTypes::M17n



# File 'lib/when_exe/calendartypes.rb', line 1314

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

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

Parameters:

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

Returns:



1173
1174
1175
1176
# File 'lib/when_exe/calendartypes.rb', line 1173

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

#enum_for(first, direction = :forward, event = @event, count_limit = nil) ⇒ Enumerator Also known as: to_enum

Enumeratorの生成

Parameters:

  • first (When::TM::TemporalPosition)

    始点

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

    昇順

    :reverse

    降順

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

    イベント名

  • count_limit (Integer) (defaults to: nil)

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

Returns:



1202
1203
1204
# File 'lib/when_exe/calendartypes.rb', line 1202

def enum_for(first, direction=:forward, event=@event, count_limit=nil)
  Enumerator.new(self, first, direction, event, count_limit)
end

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

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

Parameters:

Returns:

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


1187
1188
1189
# File 'lib/when_exe/calendartypes.rb', line 1187

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

#monthWhen::BasicTypes::M17n



# File 'lib/when_exe/calendartypes.rb', line 1310

#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 - 暦注が不一致


1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
# File 'lib/when_exe/calendartypes.rb', line 1292

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

#notes(date, options = {}) ⇒ Hash, ...

Note:

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

Note:

暦注のビットアドレスは、暦注サブクラスのNoteObjects定数の中の定義順序による。 When::CalendarTypes::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 と同じ(デフォルト)

  • :conditions (Hash)

    暦注計算の条件

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

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

Returns:

  • (Hash)

    :notes が String の場合、指定の暦注の計算結果を返す。

  • (Array<Hash>)

    上記に該当せず、:indices が Integer の場合、指定の暦座標の暦注計算結果を返す。

  • (Array<Array<Hash>>)

    上記のいずれにも該当しない場合、暦注計算結果を返す。

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


1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
# File 'lib/when_exe/calendartypes.rb', line 1253

def notes(date, options={})
  dates, indices, notes, conditions, options = _parse_note(date, options)
  _result(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
  }, options)
end

#yearWhen::BasicTypes::M17n



# File 'lib/when_exe/calendartypes.rb', line 1306