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 inherited from TM::Calendar

TM::Calendar::HashProperty

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

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

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

    生成された朔閏表定義



594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# File 'lib/when_exe/calendartypes.rb', line 594

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

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

Parameters:

  • definition (Array)

    ひな型朔閏表

  • year_range (Range) (defaults to: nil)

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

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

    差分情報

Returns:

  • (Array)

    生成された朔閏表定義



561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/when_exe/calendartypes.rb', line 561

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

朔閏表を生成する

Parameters:

  • sub_range (Range) (defaults to: nil)

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

  • length (Integer) (defaults to: nil)

    大の月の日数(ダミー)

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

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

Returns:

  • (Hash)

    朔閏表



634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/when_exe/calendartypes.rb', line 634

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_rangeRange

朔閏表の有効範囲(日)

Returns:

  • (Range)

    有効範囲(ユリウス通日)



662
663
664
# File 'lib/when_exe/calendartypes.rb', line 662

def sdn_range
   @sdn_range ||= @origin_of_LSC...(@origin_of_LSC+@rule_table['T']['Days'])
end

#within_sdn_range?(date) ⇒ Boolean

指定の日付は有効か?

Parameters:

Returns:

  • (Boolean)

    true 有効 / false 無効



672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/when_exe/calendartypes.rb', line 672

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_rangeRange

朔閏表の有効範囲

Returns:

  • (Range)

    有効範囲(西暦年)



654
655
656
# File 'lib/when_exe/calendartypes.rb', line 654

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