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
Instance Attribute Summary collapse
-
#base ⇒ Array<Integer, nil>
readonly
日時要素の下限.
-
#index_of_MSC ⇒ Integer
readonly
年/日のインデクス(index of most significant coordinate).
-
#indices ⇒ Array<When::Coordinates::Index>
readonly
インデクスオブジェクト.
-
#origin_of_LSC ⇒ Integer
readonly
日/秒の原点(origin of least significant coordinate).
-
#origin_of_MSC ⇒ Integer
readonly
年/日の原点(origin of most significant coordinate).
-
#pair ⇒ Array<Boolean>
readonly
日時要素がPairであるべきか.
-
#unit ⇒ Array<Integer, nil>
readonly
日時要素の要素数.
Instance Method Summary collapse
-
#_arrange_length(period) ⇒ Array<Numeric>
期間指定用 Array の桁数合わせ.
-
#_diff_to_CE ⇒ Integer
西暦との差.
-
#_encode(source, border = @border) ⇒ Array<Numeric>
日時要素の encode.
-
#_validate(source, other = nil, &block) ⇒ Array<Numeric>
日時要素の正規化.
-
#note ⇒ When::CalendarTypes::CalendarNote, Array<Array<klass, Array<klass, method, block>>>
代表暦注.
Methods included from Parts::MethodCash
_setup_, 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 で定義されていないメソッドは
処理を @note or @formula[0] (When::Ephemeris::Formula) に委譲する
1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 |
# File 'lib/when_exe/coordinates.rb', line 1951 def method_missing(name, *args, &block) unless When::Parts::MethodCash::Escape.key?(name) if note.respond_to?(name) 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) elsif When::Ephemeris::Formula.method_defined?(name) unless respond_to?(:forwarded_formula, true) instance_eval('class << self; include When::Ephemeris::Formula::Methods; end') @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
#base ⇒ Array<Integer, nil> (readonly)
日付/日時の外部表現の「下限」を指定する。内部表現の下限は常に 0 である。
日時要素の下限
サブクラスが定義するメソッド _coordinates_to_number, _number_to_coordinates は内部表現を使用する。
1576 1577 1578 |
# File 'lib/when_exe/coordinates.rb', line 1576 def base @base end |
#index_of_MSC ⇒ Integer (readonly)
年/日のインデクス(index of most significant coordinate)
1553 1554 1555 |
# File 'lib/when_exe/coordinates.rb', line 1553 def index_of_MSC @index_of_MSC end |
#indices ⇒ Array<When::Coordinates::Index> (readonly)
インデクスオブジェクト
1547 1548 1549 |
# File 'lib/when_exe/coordinates.rb', line 1547 def indices @indices end |
#origin_of_LSC ⇒ Integer (readonly)
日/秒の原点(origin of least significant coordinate)
1541 1542 1543 |
# File 'lib/when_exe/coordinates.rb', line 1541 def origin_of_LSC @origin_of_LSC end |
#origin_of_MSC ⇒ Integer (readonly)
年/日の原点(origin of most significant coordinate)
1535 1536 1537 |
# File 'lib/when_exe/coordinates.rb', line 1535 def origin_of_MSC @origin_of_MSC end |
#pair ⇒ Array<Boolean> (readonly)
日時要素がPairであるべきか
1586 1587 1588 |
# File 'lib/when_exe/coordinates.rb', line 1586 def pair @pair end |
#unit ⇒ Array<Integer, nil> (readonly)
日時要素の要素数
1563 1564 1565 |
# File 'lib/when_exe/coordinates.rb', line 1563 def unit @unit end |
Instance Method Details
#_arrange_length(period) ⇒ Array<Numeric>
期間指定用 Array の桁数合わせ
1632 1633 1634 1635 1636 1637 |
# File 'lib/when_exe/coordinates.rb', line 1632 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 |
#_diff_to_CE ⇒ Integer
西暦との差
1643 1644 1645 |
# File 'lib/when_exe/coordinates.rb', line 1643 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
1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 |
# File 'lib/when_exe/coordinates.rb', line 1656 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>
日付要素と時刻要素に関連がある場合、block を指定して、両者の 情報をやり取りする( yield で通日を渡し、通日を返してもらう)。
例1: 夏時間制を採用している場合、日付によって時刻の正規化の仕方が影響を受ける
例2: 日の境界が日没の場合、当該時刻が日没の前か後かで日付が変わる
日時要素の正規化
1622 1623 1624 |
# File 'lib/when_exe/coordinates.rb', line 1622 def _validate(source, other=nil, &block) return _encode(_decode(source, other, &block)) end |