Module: When::Coordinates::Temporal

Includes:
Parts::MethodCash
Defined in:
lib/when_exe/coordinates.rb

Overview

暦座標を扱う処理をまとめたモジュール

When::TM::Calendar と When::TM::Clock に共通する処理だが、ISO 19108 で両者の
直接の superclass である、When::TM::ReferenceSystem は、これらの処理を持たない
こととなっているため、When::TM::Calendar と When::TM::Clock の共通部分を
モジュールとしてまとめた。

Defined Under Namespace

Modules: IndexConversion, OriginAndUpperDigits, OriginOnly

Constant Summary collapse

HashProperty =
[[:origin_of_MSC, 0], [:origin_of_LSC, 0], [:index_of_MSC, 0], [:_diff_to_CE, 0], 
:unit, :base, :pair, :note,
:location, :time_basis, :border, :formula]

Constants included from Parts::MethodCash

Parts::MethodCash::Escape

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parts::MethodCash

_setup_, _setup_info, escape, #method_missing_

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

その他のメソッド

When::Coordinates::Temporal で定義されていないメソッドは
処理を下記に移譲する(番号は優先順位)
  When::CalendarNote
    (1) @note
    (2) SolarTerms
    (3) LunarPhases
  When::Ephemeris::Formula
    (4)@formula[0]


2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
# File 'lib/when_exe/coordinates.rb', line 2061

def method_missing(name, *args, &block)
  unless When::Parts::MethodCash::Escape.key?(name)
    if note.respond_to?(name)
      if note.class::CalendarDepend
        instance_eval %Q{
          def #{name}(*args, &block)
            @note.send("#{name}", *(args + [self]), &block)
          end
        } unless When::Parts::MethodCash.escape(name)
        return @note.send(name, *(args + [self]), &block)
      else
        instance_eval %Q{
          def #{name}(*args, &block)
            @note.send("#{name}", *args, &block)
          end
        } unless When::Parts::MethodCash.escape(name)
        return @note.send(name, *args, &block)
      end
    end
    ['SolarTerms', 'LunarPhases'].each do |note|
      if When.CalendarNote(note).respond_to?(name)
        instance_eval %Q{
          def #{name}(*args, &block)
            When.CalendarNote("#{note}").send("#{name}", *args, &block)
          end
        } unless When::Parts::MethodCash.escape(name)
        return When.CalendarNote(note).send(name, *args, &block)
      end
    end
    if When::Ephemeris::Formula.method_defined?(name)
      unless respond_to?(:forwarded_formula, true)
        extend When::Ephemeris::Formula::ForwardedFormula
        @formula ||= When::Ephemeris::Formula.new({:location=>@location})
        @formula   = When.Resource(Array(@formula), '_ep:')
      end
      instance_eval %Q{
        def #{name}(*args, &block)
          forward = forwarded_formula("#{name}", args[0])
          return forward.send("#{name}", *args, &block) if forward
          _method_missing("#{name}", *args, &block)
        end
      } unless When::Parts::MethodCash.escape(name)
      forward = forwarded_formula(name, args[0])
      return forward.send(name, *args, &block) if forward
    end
  end
  _method_missing(name, *args, &block)
end

Instance Attribute Details

#baseArray<Integer, nil> (readonly)

Note:

日付/日時の外部表現の「下限」を指定する。内部表現の下限は常に 0 である。

日時要素の下限

サブクラスが定義するメソッド _coordinates_to_number, _number_to_coordinates は内部表現を使用する。

Returns:

  • (Array<Integer, nil>)

    Ex. [nil, 1, 1], [nil, 0, 0, 0]

    初期化時に indices から自動生成する



1656
1657
1658
# File 'lib/when_exe/coordinates.rb', line 1656

def base
  @base
end

#index_of_MSCInteger (readonly)

年/日のインデクス(index of most significant coordinate)

Returns:

  • (Integer)


1633
1634
1635
# File 'lib/when_exe/coordinates.rb', line 1633

def index_of_MSC
  @index_of_MSC
end

#indicesArray<When::Coordinates::Index> (readonly)

インデクスオブジェクト



1627
1628
1629
# File 'lib/when_exe/coordinates.rb', line 1627

def indices
  @indices
end

#origin_of_LSCInteger (readonly)

日/秒の原点(origin of least significant coordinate)

Returns:

  • (Integer)


1621
1622
1623
# File 'lib/when_exe/coordinates.rb', line 1621

def origin_of_LSC
  @origin_of_LSC
end

#origin_of_MSCInteger (readonly)

年/日の原点(origin of most significant coordinate)

Returns:

  • (Integer)


1615
1616
1617
# File 'lib/when_exe/coordinates.rb', line 1615

def origin_of_MSC
  @origin_of_MSC
end

#pairArray<Boolean> (readonly)

日時要素がPairであるべきか

Returns:

  • (Array<Boolean>)

    Ex. [false] * 3, [false] * 4

    初期化時に indices から自動生成する



1666
1667
1668
# File 'lib/when_exe/coordinates.rb', line 1666

def pair
  @pair
end

#unitArray<Integer, nil> (readonly)

日時要素の要素数

Returns:

  • (Array<Integer, nil>)

    Ex. [nil, 12], [nil, 24, 60, 60]

    初期化時に indices から自動生成する



1643
1644
1645
# File 'lib/when_exe/coordinates.rb', line 1643

def unit
  @unit
end

Instance Method Details

#_arrange_length(period) ⇒ Array<Numeric>

期間指定用 Array の桁数合わせ

Parameters:

Returns:



1715
1716
1717
1718
1719
1720
# File 'lib/when_exe/coordinates.rb', line 1715

def _arrange_length(period)
  return period unless period.kind_of?(Array)
  diff = @indices.length - period.length + 1
  return period if (diff == 0)
  return (diff > 0) ? Array.new(diff, 0) + period : period[(-diff)..-1]
end

#_default_startObject

対応する ::Date の start 属性



1733
1734
1735
# File 'lib/when_exe/coordinates.rb', line 1733

def _default_start
  ::Date::GREGORIAN
end

#_diff_to_CEInteger

西暦との差

Returns:

  • (Integer)

    暦法の年の桁と西暦とのずれ



1726
1727
1728
# File 'lib/when_exe/coordinates.rb', line 1726

def _diff_to_CE
  @_diff_to_CE ||= @epoch_in_CE ? @epoch_in_CE - @origin_of_MSC : 0
end

#_encode(source, border = @border) ⇒ Array<Numeric>

日時要素の encode

Parameters:

  • source (Array<Numeric>)

    日時要素の内部表現に対応する Array

Returns:

  • (Array<Numeric>)

    日時要素の外部表現に対応する Array



1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
# File 'lib/when_exe/coordinates.rb', line 1746

def _encode(source, border=@border)
  # source は非破壊
  date = source.dup

  # 外部表現に戻す
  date[0] = +date[0]
  (@base.length-1).downto(@unit.length-1) do |i|
    date[i] = _from_index(date[0..i]) || date[i] + (@base[i]||0)
  end
  date[0] = source[0]

  # 結果を反映
  date = border._adjust_epoch(date, self) if border
  _encode_upper_structure(date)
end

#_validate(source, other = nil, &block) ⇒ Array<Numeric>

Note:

日付要素と時刻要素に関連がある場合、block を指定して、両者の 情報をやり取りする( yield で通日を渡し、通日を返してもらう)。

例1: 夏時間制を採用している場合、日付によって時刻の正規化の仕方が影響を受ける

例2: 日の境界が日没の場合、当該時刻が日没の前か後かで日付が変わる

日時要素の正規化

Parameters:

  • source (Array<Numeric>)

    正規化しようとしている日時要素の Array

  • other (Array<Numeric>) (defaults to: nil)

    日時要素ごとに加減算を行う場合、加減算量の Array を指定する

  • block (Block)

Returns:

  • (Array<Numeric>)

    正規化された日時要素の Array

    日時要素は、それぞれの When::TM::Calendar や When::TM::Clock の実装に応じて有効な値となっている。



1705
1706
1707
# File 'lib/when_exe/coordinates.rb', line 1705

def _validate(source, other=nil, &block)
  return _encode(_decode(source, other, &block))
end

#noteWhen::CalendarNote, Array<Array<klass, Array<klass, method, block>>>

代表暦注

Returns:

  • (When::CalendarNote)
  • (Array<Array<klass, Array<klass, method, block>>>)

    最外側のArray要素は年・月・日に対応

    klass [String, When::CalendarNote, When::Coordinates::Residue]

    method [String, Symbol] (デフォルト ‘day’, ‘month’ or ‘year’ (対応する桁による))

    block [Block] (デフォルト なし)



1679
1680
1681
1682
1683
1684
1685
# File 'lib/when_exe/coordinates.rb', line 1679

def note
  case @note
  when String ; @note = When.CalendarNote(@note)
  when Array  ; @note = When::CalendarNote.new(*@note)
  end
  @note
end