Class: When::CalendarTypes::PatternTableBasedLuniSolar

Inherits:
TableBased show all
Includes:
Lunar
Defined in:
lib/when_exe/calendartypes.rb

Overview

表引きにより実現する太陰太陽暦

Luni-Solar calendar which uses year / month /day table

Constant Summary

Constants included from Lunar

Lunar::Pattern

Constants included from When::Coordinates

When::Coordinates::Bahai, When::Coordinates::Common, When::Coordinates::DefaultDateIndices, When::Coordinates::DefaultDayIndex, When::Coordinates::DefaultTimeIndices, When::Coordinates::Indian, When::Coordinates::Iranian, When::Coordinates::Javanese, When::Coordinates::MATCH, When::Coordinates::Mayan, When::Coordinates::PERIOD, When::Coordinates::PERIOD_NAME, When::Coordinates::PRECISION, When::Coordinates::PRECISION_NAME, When::Coordinates::Tibetan, When::Coordinates::VALUE, When::Coordinates::Yi

Constants included from Parts::Resource

Parts::Resource::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty

Instance Attribute Summary

Attributes inherited from TM::Calendar

#reference_frame, #time_basis

Attributes included from TimeStandard::TimeBasis

#_time_basis

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Lunar

#_verify, #verify

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

#_normalize_time_basis

Methods included from When::Coordinates

to_deg, to_deg_225, to_dms

Methods inherited from TM::ReferenceSystem

#domain, #name

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, #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

Class Method Details

.join(definitions, difference = {}) ⇒ Array

複数のひな型朔閏表からの差分で朔閏表を生成する

Parameters:

  • definitions ([Array<Array<String, Range>>])

    ひな型朔閏表

    • String - もとにする太陰太陽暦のIRI文字列

    • Range - 朔閏表の年代範囲(デフォルトはもとにする太陰太陽暦の年代範囲)

  • difference (Hash{Integer=>(String or Hash{String or Regexp=>String})}) (defaults to: {})

    差分情報

Returns:

  • (Array)

    生成された朔閏表定義



620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'lib/when_exe/calendartypes.rb', line 620

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, range = nil, difference = {}) ⇒ Array

ひとつのひな型朔閏表からの差分で朔閏表を生成する

Parameters:

  • definition (Array)

    ひな型朔閏表

  • range (Range) (defaults to: nil)

    生成する朔閏表の年代範囲

  • difference (Hash{Integer=>(String or Hash{String or Regexp=>String})}) (defaults to: {})

    差分情報

Returns:

  • (Array)

    生成された朔閏表定義



587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
# File 'lib/when_exe/calendartypes.rb', line 587

def patch(definition, range=nil, difference={})
  When.Calendar(definition)
  base    = When::CalendarTypes.const_get(definition)
  hash    = base[-1].dup
  range ||= hash['origin_of_MSC']...(hash['origin_of_MSC']+hash['rule_table'].size)
  range   = range.to_a
  hash['origin_of_LSC'] += hash['rule_table'][range[0]-hash['origin_of_MSC']][1]
  hash['rule_table']     = 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']  = range[0]
  base[0..-2] + [hash]
end

Instance Method Details

#lunar_table(sub_range = nil, length = nil, duration = nil) ⇒ Hash

朔閏表を生成する

Parameters:

  • sub_range (Range) (defaults to: nil)

    生成範囲(西暦年) デフォルトは self.range

  • length (Integer) (defaults to: nil)

    大の月の日数(ダミー)

  • duration (When::TM::Duration) (defaults to: nil)

    チェックする月の間隔(ダミー)

Returns:

  • (Hash)

    朔閏表



660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
# File 'lib/when_exe/calendartypes.rb', line 660

def lunar_table(sub_range=nil, length=nil, duration=nil)
  sub_range ||= 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 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

#rangeRange

朔閏表の有効範囲

Returns:

  • (Range)

    有効範囲(西暦年)



680
681
682
# File 'lib/when_exe/calendartypes.rb', line 680

def range
   @origin_of_MSC...(@origin_of_MSC+@rule_table['T']['Rule'].length)
end