Class: When::CalendarNote
- Inherits:
-
TM::ReferenceSystem
- Object
- BasicTypes::Object
- TM::Object
- TM::ReferenceSystem
- When::CalendarNote
- Defined in:
- lib/when_exe/calendarnote.rb,
lib/when_exe/region/bahai.rb,
lib/when_exe/region/mayan.rb,
lib/when_exe/region/indian.rb,
lib/when_exe/region/chinese.rb,
lib/when_exe/region/martian.rb,
lib/when_exe/region/russian.rb,
lib/when_exe/region/tibetan.rb,
lib/when_exe/ephemeris/notes.rb,
lib/when_exe/region/javanese.rb,
lib/when_exe/region/chinese/notes.rb,
lib/when_exe/region/japanese/notes.rb,
lib/when_exe/region/japanese/weeks.rb,
lib/when_exe.rb
Overview
Copyright (C) 2014-2017 Takashi SUGA
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
Direct Known Subclasses
Balinese, ChineseLuniSolar, Christian, Ephemeris, HinduNote, Japanese, JapaneseLuniSolarNote, JapaneseSolarNote, LuniSolarPositions, Roman, Week, Zoroastrian
Defined Under Namespace
Modules: NoteElement, NotesContainer Classes: Balinese, ChineseLuniSolar, ChineseSolar, Christian, DarianWeek, DiscordianWeek, Enumerator, Ephemeris, HinduNote, HinduNoteDetailed, InternationalFixedWeek, Japanese, JapaneseLuniSolarNote, JapaneseSolarNote, LunarPhases, LuniSolarPositions, PositivistWeek, RokuyoWeek, Roman, ShireWeek, SolarTerms, SolarTermsRevised, SovietFiveDayWeek, SovietSixDayWeek, TranquilityWeek, Week, WorldSeasonWeek, WorldWeek, Zoroastrian
Constant Summary collapse
- CalendarDepend =
暦法によってイベントの動作を変えるか否か
false
- Bahai =
[['Bahai::YearName'], ['_m:Bahai::Month'], ['Common::Week']]
- Mayan =
[{},['Mayan#{?Epoch=Epoch}::Trecena::Trecena', 'Mayan#{?Epoch=Epoch}::Tzolk\'in', 'Mayan#{?Epoch=Epoch}::Lords_of_the_Night', 'Mayan#{?Epoch=Epoch}::Haab\'']]
- Yis =
[['Yi::YearName'], ['_m:Calendar::Month'], ['Common::Week']]
- CommonWithSovietFiveDay =
標準の暦注 + 五曜
[['_m:Calendar::Month'], ['Common::Week', '_n:SovietFiveDayWeek/Notes::day::FiveDay']]
- CommonWithSovietSixDay =
標準の暦注 + 六曜
[['_m:Calendar::Month'], ['Common::Week', '_n:SovietSixDayWeek/Notes::day::SixDay']]
- Tibetan =
[['Tibetan::干支'], ['_m:Calendar::Month'], ['Common::Week']]
- Javanese =
[['Javanese::Windu'], ['_m:Calendar::Month'], ['Javanese::Pasaran', 'Javanese::Paringkelan', 'Javanese::Week', 'Javanese::Wuku']]
- CommonWithRokuyo =
標準の暦注 + 六曜
[['_m:Calendar::Month'], ['Common::Week', '_n:RokuyoWeek/Notes::day::Rokuyo']]
- Default =
[['_m:Calendar::Month'], ['Common::Week']]
- JulianDay =
[['Common::Week', 'Common::干支']]
- Chinese =
[['Common::干支'], ['_m:Calendar::Month'], ['Common::Week', 'Common::干支']]
Constants included from Namespace
Namespace::DC, Namespace::DCQ, Namespace::DCT, Namespace::FOAF, Namespace::OWL, Namespace::RDF, Namespace::RDFC, Namespace::RDFS, Namespace::RSS, Namespace::XSD
Instance Attribute Summary collapse
-
#event ⇒ String
readonly
デフォルトイベント名.
Attributes inherited from TM::ReferenceSystem
#domain_of_validity, #position
Attributes inherited from BasicTypes::Object
Attributes included from Parts::Resource
#child, #keys, #locale, #namespace
Instance Method Summary collapse
-
#copy(event) ⇒ When::CalendarNote
デフォルトイベントの指定.
- #day ⇒ When::BasicTypes::M17n
-
#duration(event = @event) ⇒ When::TM::PeriodDuration
典型的なイベントの発生間隔.
-
#enum_for(*args) ⇒ Enumerator
(also: #to_enum)
Enumeratorの生成.
-
#include?(date, event = @event) ⇒ Boolean
指定の日時が指定イベントに該当するか?.
- #month ⇒ When::BasicTypes::M17n
-
#note?(date, options = {}) ⇒ Boolean
暦注の一致 or 不一致.
-
#notes(date, options = {}) ⇒ Array<Array<Hash>>
暦注の計算.
- #year ⇒ When::BasicTypes::M17n
Methods inherited from TM::ReferenceSystem
Methods included from Parts::Resource
#[], #^, _instance, _setup_, _setup_info, base_uri, #each, #hierarchy, #included?, #iri, #leaf?, #m17n, #map, #parent, #registered?, root_dir
Methods included from Parts::Resource::Pool
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class When::Parts::Resource
Instance Attribute Details
#event ⇒ String
イベント名の後ろに数字が使われている場合、数字部分以降はイベントメソッドの引数になります。 SolarTermsクラスで 'term180' は、太陽黄経180度のイベントすなわち秋分を意味します。
デフォルトイベント名
214 215 216 |
# File 'lib/when_exe/calendarnote.rb', line 214 def event @event end |
Instance Method Details
#copy(event) ⇒ When::CalendarNote
デフォルトイベントの指定
223 224 225 226 227 |
# File 'lib/when_exe/calendarnote.rb', line 223 def copy(event) c = self.clone c.send(:event=, event) c end |
#duration(event = @event) ⇒ When::TM::PeriodDuration
典型的なイベントの発生間隔
235 236 237 238 |
# File 'lib/when_exe/calendarnote.rb', line 235 def duration(event=@event) void, event, parameter = event.split(/\A([^\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の生成
274 275 276 277 278 279 280 281 |
# File 'lib/when_exe/calendarnote.rb', line 274 def enum_for(*args) params = args.dup = params[-1].kind_of?(Hash) ? params.pop.dup : {} [:event] ||= @event self.class::Enumerator.new(*(params[0].kind_of?(Range) ? [self, params[0], ] : [self, params[0], params[1] || :forward, ])) end |
#include?(date, event = @event) ⇒ Boolean
指定の日時が指定イベントに該当するか?
249 250 251 |
# File 'lib/when_exe/calendarnote.rb', line 249 def include?(date, event=@event) enum_for(date, :forward, event.downcase).next.include?(date) end |
#note?(date, options = {}) ⇒ Boolean
暦注の一致 or 不一致
360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/when_exe/calendarnote.rb', line 360 def note?(date, ={}) = _find_note() if .kind_of?(String) || .kind_of?(Regexp) pattern = .delete(:value) if .kind_of?(Hash) result = notes(date, ) 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 NotesContainer.verify(pattern, hash[:value]) end return false end |
#notes(date, options = {}) ⇒ Array<Array<Hash>>
CalendarNoteオブジェクト生成時に _normalize メソッド内で @prime 変数を設定しておけば、 本メソッドの :prime オプションで参照される。(Balinese#_normalize等参照)
暦注のビットアドレスは、暦注サブクラスのNotes定数の中の定義順序による。 When::CalendarNote クラスの場合 new の引数とした暦注要素リストの定義順序による。 ビットアドレスの値が 1 の暦注が計算対象となる。
戻り値の :value が When::TM::TemporalPosition の場合、その日時オブジェクトの events に暦注名の入った 暦注に該当する日付である。(例) Christian クラス で easter を計算した場合、当該年の復活祭の日付オブジェクトが返る。
暦注サブクラスの場合、暦注要素が増えたり、:note の暦注要素の型が変わったりすることがある。
暦注の計算
329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/when_exe/calendarnote.rb', line 329 def notes(date, ={}) dates, indices, notes, persistence, conditions, = _parse_note(date, ) retrieved = NotesContainer.retrieve(persistence, date.to_i) return retrieved if retrieved NotesContainer.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| notes_hash[note] ||= _note_element(note, i, conditions, dates) end notes_hash end }, persistence, date.to_i) end |