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 © 2014 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: LabelAccess, NotesContainer Classes: Balinese, ChineseLuniSolar, ChineseSolar, Christian, DarianWeek, DiscordianWeek, Enumerator, Ephemeris, HinduNote, HinduNoteDetailed, InternationalFixedWeek, Japanese, JapaneseLuniSolarNote, JapaneseSolarNote, LunarPhases, LuniSolarPositions, NoteElement, PositivistWeek, RokuyoWeek, Roman, ShireWeek, SolarTerms, SolarTermsRevised, SovietFiveDayWeek, SovietSixDayWeek, TranquilityWeek, Week, WorldSeasonWeek, WorldWeek, Zoroastrian
Constant Summary collapse
- CalendarDepend =
暦法によってイベントの動作を変えるか否か
false
- HashProperty =
[:event]
- 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 Parts::Resource
Parts::Resource::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIDecode, Parts::Resource::IRIDecodeTable, Parts::Resource::IRIEncode, Parts::Resource::IRIEncodeTable, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty
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
#_pool, #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
#[], #^, _abbreviation_to_iri, _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
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度のイベントすなわち秋分を意味します。
デフォルトイベント名
220 221 222 |
# File 'lib/when_exe/calendarnote.rb', line 220 def event @event end |
Instance Method Details
#copy(event) ⇒ When::CalendarNote
デフォルトイベントの指定
229 230 231 232 233 |
# File 'lib/when_exe/calendarnote.rb', line 229 def copy(event) c = self.clone c.send(:event=, event) c end |
#duration(event = @event) ⇒ When::TM::PeriodDuration
典型的なイベントの発生間隔
241 242 243 244 |
# File 'lib/when_exe/calendarnote.rb', line 241 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の生成
280 281 282 283 284 285 286 287 |
# File 'lib/when_exe/calendarnote.rb', line 280 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
指定の日時が指定イベントに該当するか?
255 256 257 |
# File 'lib/when_exe/calendarnote.rb', line 255 def include?(date, event=@event) enum_for(date, :forward, event.downcase).next.include?(date) end |
#note?(date, options = {}) ⇒ Boolean
暦注の一致 or 不一致
366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/when_exe/calendarnote.rb', line 366 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 の暦注要素の型が変わったりすることがある。
暦注の計算
335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/when_exe/calendarnote.rb', line 335 def notes(date, ={}) dates, indices, notes, persistence, conditions, = _parse_note(date, ) retrieved = NotesContainer.retrieve(persistence, date.to_i) return retrieved unless retrieved == false 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 |