Class: When::CalendarTypes::PatternTableBasedLuniSolar
- Inherits:
-
TableBased
- Object
- BasicTypes::Object
- TM::Object
- TM::ReferenceSystem
- TM::Calendar
- TableBased
- When::CalendarTypes::PatternTableBasedLuniSolar
- Includes:
- Lunar
- Defined in:
- lib/when_exe/calendartypes.rb
Overview
表引きにより実現する太陰太陽暦
Luni-Solar calendar which uses year / month /day table
Direct Known Subclasses
PatternTableBasedLuniSolarExtended, PatternTableBasedLuniSolarWithEphemeris, PatternTableBasedSolar
Constant Summary
Constants included from Lunar
Constants inherited from TM::Calendar
Constants included from When::Coordinates
When::Coordinates::Bahai, When::Coordinates::Chinese, When::Coordinates::Common, When::Coordinates::DefaultDateIndices, When::Coordinates::DefaultDayIndex, When::Coordinates::DefaultTimeIndices, When::Coordinates::Indian, When::Coordinates::Iranian, When::Coordinates::Javanese, When::Coordinates::LocationTable, When::Coordinates::MATCH, When::Coordinates::Mayan, When::Coordinates::PERIOD, When::Coordinates::PERIOD_NAME, When::Coordinates::PRECISION, When::Coordinates::PRECISION_NAME, When::Coordinates::Russian, When::Coordinates::Tibetan, When::Coordinates::VALUE, When::Coordinates::Yi
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
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
Attributes inherited from TM::Calendar
#diff_to_CE, #epoch_in_CE, #reference_frame, #time_basis
Attributes included from TimeStandard::TimeBasis
Attributes inherited from TM::ReferenceSystem
#domain_of_validity, #position
Attributes inherited from BasicTypes::Object
Attributes included from Parts::Resource
#_pool, #child, #keys, #locale, #namespace
Class Method Summary collapse
-
.join(definitions, difference = {}) ⇒ Array
複数のひな型朔閏表からの差分で朔閏表を生成する.
-
.patch(definition, year_range = nil, difference = {}) ⇒ Array
ひとつのひな型朔閏表からの差分で朔閏表を生成する.
Instance Method Summary collapse
-
#lunar_table(sub_range = nil, length = nil, duration = nil) ⇒ Hash
朔閏表を生成する.
-
#sdn_range ⇒ Range
朔閏表の有効範囲(日).
-
#within_sdn_range?(date) ⇒ Boolean
指定の日付は有効か?.
-
#year_range ⇒ Range
朔閏表の有効範囲.
Methods included from Lunar
Methods inherited from TableBased
#_coordinates_to_number, #_length, #_number_to_coordinates
Methods inherited from TM::Calendar
#_new_month_, _setup_, #_to_month_number_, #date_trans, #jul_trans, #rate_of_clock, #strftime, #time_standard, #to_cal_date, #to_julian_date, #to_universal_time
Methods included from TimeStandard::TimeBasis
Methods included from When::Coordinates
to_deg, to_deg_225, to_dms, utf_gets
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, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #parent, #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
Class Method Details
.join(definitions, difference = {}) ⇒ Array
複数のひな型朔閏表からの差分で朔閏表を生成する
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 |
# File 'lib/when_exe/calendartypes.rb', line 629 def join(definitions, difference={}) if definitions.first.kind_of?(Array) base = When::CalendarTypes.const_get(definitions.first[0]).dup else base = [] base << definitions.shift until definitions.first.kind_of?(Array) end tables = definitions.map {|definition| When.Calendar(definition[0]).lunar_table(definition[1]) } hash = base.pop.merge({ 'origin_of_MSC' => tables.first['origin_of_MSC'], 'origin_of_LSC' => tables.first['origin_of_LSC'], 'rule_table' => tables.inject([]) {|rules, table| rules += table['rule_table']} }) difference.each_pair do |year, pattern| offset = year - hash['origin_of_MSC'] hash['rule_table'][offset] = if pattern.kind_of?(Hash) rule = hash['rule_table'][offset].dup pattern.each_pair do |key,value| raise ArgumentError, "Can't patch \"#{rule}\" by {#{key}=>#{value}} at #{year}" unless rule.sub!(key,value) end rule else pattern end end base << hash end |
.patch(definition, year_range = nil, difference = {}) ⇒ Array
ひとつのひな型朔閏表からの差分で朔閏表を生成する
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/when_exe/calendartypes.rb', line 596 def patch(definition, year_range=nil, difference={}) When.Calendar(definition) base = When::CalendarTypes.const_get(definition) hash = base[-1].dup year_range ||= hash['origin_of_MSC']...(hash['origin_of_MSC']+hash['rule_table'].size) year_range = year_range.to_a hash['origin_of_LSC'] += hash['rule_table'][year_range[0]-hash['origin_of_MSC']][1] hash['rule_table'] = year_range.map {|year| original = hash['rule_table'][year-hash['origin_of_MSC']][0] case difference[year] when String ; next difference[year] when nil ; next original end original = original.dup difference[year].each_pair {|key,value| raise ArgumentError, "Can't patch \"#{original}\" by {#{key}=>#{value}} at #{year}" unless original.sub!(key,value) } original } hash['origin_of_MSC'] = year_range[0] base[0..-2] + [hash] end |
Instance Method Details
#lunar_table(sub_range = nil, length = nil, duration = nil) ⇒ Hash
朔閏表を生成する
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'lib/when_exe/calendartypes.rb', line 669 def lunar_table(sub_range=nil, length=nil, duration=nil) sub_range ||= year_range last = sub_range.last last -= 1 if sub_range.exclude_end? [sub_range.first, last].each do |edge| raise RangeError, 'Range exceeded: ' + sub_range.to_s unless year_range.include?(edge) end { 'origin_of_MSC' => sub_range.first, 'origin_of_LSC' => @origin_of_LSC + @rule_table['T']['Rule'][sub_range.first-@origin_of_MSC][1], 'rule_table' => sub_range.to_a.map {|year| @rule_table['T']['Rule'][year-@origin_of_MSC][0] } } end |
#sdn_range ⇒ Range
朔閏表の有効範囲(日)
697 698 699 |
# File 'lib/when_exe/calendartypes.rb', line 697 def sdn_range @sdn_range ||= @origin_of_LSC...(@origin_of_LSC+@rule_table['T']['Days']) end |
#within_sdn_range?(date) ⇒ Boolean
指定の日付は有効か?
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
# File 'lib/when_exe/calendartypes.rb', line 707 def within_sdn_range?(date) date = date.to_i return true if sdn_range.include?(date) if date <= sdn_range.first case @before when PatternTableBasedLuniSolar; @before.within_sdn_range?(date) when false, nil ; false else ; true end else case @after when PatternTableBasedLuniSolar; @after.within_sdn_range?(date) when false, nil ; false else ; true end end end |
#year_range ⇒ Range
朔閏表の有効範囲
689 690 691 |
# File 'lib/when_exe/calendartypes.rb', line 689 def year_range @origin_of_MSC...(@origin_of_MSC+@rule_table['T']['Rule'].length) end |