Class: When::TM::CalDate

Inherits:
TemporalPosition show all
Defined in:
lib/when_exe/tmposition.rb,
lib/when_exe/linkeddata.rb,
lib/when_exe/inspect.rb

Overview

When::TM::CalDate への追加

Direct Known Subclasses

DateAndTime

Constant Summary collapse

SearchOption =

検索オプション

{After=>[0, -2, Before], Before=>[-2, 0, After]}

Constants inherited from TemporalPosition

TemporalPosition::AMPM, TemporalPosition::DateTimeInstanceMethods, TemporalPosition::Format, TemporalPosition::HashProperty

Constants included from Coordinates

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

Constants included from When

CENTURY, DAY, DECADE, EUCJP, HOUR, MINUTE, MONTH, MinusInfinity, Month, P1D, P1M, P1W, P1Y, PT1H, PT1M, PT1S, PlusInfinity, RootDir, SECOND, STRING, SYSTEM, SourceURI, When::TimeValue, UTF8, VERSION, W31J, WEEK, Week, YEAR

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 IndeterminateValue

IndeterminateValue::After, IndeterminateValue::Before, IndeterminateValue::I, IndeterminateValue::Max, IndeterminateValue::Min, IndeterminateValue::Now, IndeterminateValue::S, IndeterminateValue::Unknown

Instance Attribute Summary collapse

Attributes inherited from TemporalPosition

#events, #frame, #indeterminated_position, #location, #options, #precision, #query, #trans

Attributes included from Parts::Resource

#_pool, #child, #keys, #locale, #namespace

Instance Method Summary collapse

Methods inherited from TemporalPosition

#+, #+@, #-, #<=>, #==, #[], #^, _instance, #_notes, _options, _setup_, _setup_info, _temporal_position, #_to_s, _verify, #clock_name, #copy, #dynamical_time, format, #has_next?, #has_time?, #include?, #inspect, #is?, #month_included, #note?, #notes, #period, #prev, #rate_of_clock, #scan, #strftime, #succ, #time_standard, #to_clock_time, #to_date, #to_datetime, #to_f, #to_time, #to_uri, #to_uri_escape, #week_included, #year_included

Methods included from Coordinates

to_deg, to_deg_225, to_dms

Methods included from When

Border, Calendar, CalendarEra, CalendarNote, Clock, Duration, Index, Location, M17n, MonthName, Pair, Residue, Resource, TemporalPosition, Wikipedia, _const_missing, _define_common_calendar_types, _setup_, _setup_info, at, client, column, config, const_missing, era, free_conv, m17n, now, server, today, when?

Methods included from TemporalPosition::Conversion

#julian_date, #tm_pos

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, #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::TM::TemporalPosition

Instance Attribute Details

#cal_dateArray<Numeric> (readonly) Also known as: calDate

Note:

ISO19108 では sequence<Integer> だが、閏月などが表現可能なよう Numeric としている。

日付要素

Returns:



1605
1606
1607
# File 'lib/when_exe/tmposition.rb', line 1605

def cal_date
  @cal_date
end

#calendar_eraWhen::TM::CalendarEra Also known as: calendarEra

暦年代



1620
1621
1622
# File 'lib/when_exe/tmposition.rb', line 1620

def calendar_era
  @calendar_era
end

#calendar_era_propsArray

暦年代属性

Returns:

  • (Array)

    ( name, epoch, reverse, go back )

    • name [String] 暦年代名

    • epoch [Integer] 使用する When::TM::Calendar で暦元に対応する年

    • reverse [Boolean] 年数が昇順(false,nil)か降順(true)か

    • go back [Boolean] 参照イベントより前の暦日か(true)、否か(false,nil)



1632
1633
1634
# File 'lib/when_exe/tmposition.rb', line 1632

def calendar_era_props
  @calendar_era_props
end

Instance Method Details

#%(other) ⇒ Numeric

ユリウス日または通年の剰余

Parameters:

Returns:

Raises:

  • (TypeError)


1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
# File 'lib/when_exe/tmposition.rb', line 1791

def %(other)
  raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue)
  if precision <= When::YEAR && other.units['year'] && other.event != 'year'
    other.to('year') % (most_significant_coordinate + @frame.epoch_in_CE)
  else
    case other.event
    when 'day'  ; other % least_significant_coordinate
    when 'year' ; other % (most_significant_coordinate + @frame.epoch_in_CE)
    else        ; raise ArgumentError,"The right operand should have a unit 'day' or 'year'"
    end
  end
end

#&(other) ⇒ When::TM::CalDate

ユリウス日または通年が指定の剰余となる日

Parameters:

Returns:

Raises:

  • (TypeError)


1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
# File 'lib/when_exe/tmposition.rb', line 1761

def &(other)
  raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue)
  case other.event
  when 'day'
  # 指定の剰余となる日
    sdn      = other & to_i
    options  = {:date=>_date_with_era(@frame.to_cal_date(sdn)), :events=>nil, :query=>@query, :validate=>:done}
    options[:precision] = When::DAY if precision < When::DAY
    result   = self.dup._copy(options)
    result.send(:_force_euqal_day, sdn-result.to_i)

  when 'year'
  # 指定の剰余となる年
    date     = @frame.send(:_decode, _date_without_era)
    date[0]  = (other & (date[0] + @frame.diff_to_CE)) - @frame.diff_to_CE
    options  = {:date=>_date_with_era(@frame.send(:_encode, date)), :events=>nil, :query=>@query}
    options[:precision] = When::YEAR if precision < When::YEAR
    return self.dup._copy(options)

  else
    raise ArgumentError,"The right operand should have a unit 'day' or 'year'"
  end
end

#_attrObject

属性の Hash



1860
1861
1862
# File 'lib/when_exe/tmposition.rb', line 1860

def _attr
  super.merge({:era_name=>@calendar_era_props, :era=>@calendar_era})
end

#_event_form(other = nil, options = {}) ⇒ String

Note:

events 配列なし - 日時をそのまま文字列化 日時の精度が日より細かい - イベント名(イベント時刻) 日時の精度が日 - イベント名(当日までの経過日数)

event を 文字列化 - 日時で与えられた event を文字列化する

Parameters:

  • other (When::TM::TemporalPosition) (defaults to: nil)

    時系の歩度を比較する基準(nilは比較しない)

  • options (Hash) (defaults to: {})

    下記の通り

Options Hash (options):

  • :precision (Numeric)

    イベント名(イベント)出力の場合の時刻の丸め位置(nilなら丸めない)

  • :method (Symbol)

    変換に用いるメソッド(:to_m17n のとき多言語文字列化)

Returns:



1322
1323
1324
1325
1326
1327
1328
1329
1330
# File 'lib/when_exe/inspect.rb', line 1322

def _event_form(other=nil, options={})
  return options[:method]==:to_m17n ? to_m17n : self unless events
  return events[0] + '(' + _clk_time_for_inspect(options[:precision]).
    to_s(options[:precision] || precision)[/[:*=0-9]+/] + ')' if precision > When::DAY
  return events[0] unless other
  other = JulianDate.dynamical_time(other.dynamical_time,
            {:time_standard=>time_standard}) unless time_standard.rate_of_clock == other.time_standard.rate_of_clock
  events[0] + '('  + (other.to_i - to_i).to_s + ')'
end

#_to_h(options = {}) ⇒ Hash

Hash 化

Parameters:

  • options (String) (defaults to: {})

    { :notes => String } という Hash の指定と等価

  • options (Integer) (defaults to: {})

    { :indices => Integer } という Hash の指定と等価

  • options (Hash) (defaults to: {})

    下記のとおり

Options Hash (options):

Returns:

  • (Hash)
    • :calendar calendar_name の結果 ( name, epoch, reverse, go back )

      • name 暦法または暦年代 (When::TM::Calendar, When::TM::CalendarEra)

      • epoch 暦元 (Integer)

      • reverse 暦年の順序 (Boolean)

        [ false, nil 昇順 ]
        [ true       降順 ]
        
      • go back 参照イベントより前の暦日か(Boolean)

        [ false, nil 否   ]
        [ true       然り ]
        
    • :cal_date cal_date の内容 (year, month, day)

      [ year  - 年 ({Numeric}) ]
      [ month - 月 ({Numeric}) ]
      [ day   - 日 ({Numeric}) ]
      
    • :clk_time to_clock_time の結果 ( 日, 時, 分, 秒 )

    • :notes Hash (の Array (の Array)) - _notes(options)



1114
1115
1116
# File 'lib/when_exe/inspect.rb', line 1114

def _to_h(options={})
  super.update({:cal_date=>@cal_date})
end

#calendar_era_epochInteger

暦年代元期

Returns:

  • (Integer)

    使用する When::TM::Calendar で暦元に対応する年



1648
1649
1650
# File 'lib/when_exe/tmposition.rb', line 1648

def calendar_era_epoch
  @calendar_era_props ?  @calendar_era_props[1] : 0
end

#calendar_era_go_backBoolean

暦年代遡及

Returns:

  • (Boolean)

    参照イベントより前の暦日か(true)、否か(false,nil)



1664
1665
1666
# File 'lib/when_exe/tmposition.rb', line 1664

def calendar_era_go_back
  @calendar_era_props ? @calendar_era_props[3] : false
end

#calendar_era_nameString Also known as: calendarEraName

暦年代名

Returns:



1639
1640
1641
# File 'lib/when_exe/tmposition.rb', line 1639

def calendar_era_name
  @calendar_era_props ? @calendar_era_props[0] : nil
end

#calendar_era_reverseBoolean

暦年代正逆

Returns:

  • (Boolean)

    年数が昇順(false,nil)か降順(true)か



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

def calendar_era_reverse
  @calendar_era_props ? @calendar_era_props[2] : false
end

#calendar_nameArray

暦法名

Returns:

  • (Array)

    ( name, epoch, reverse, go back )

    • name 暦法または暦年代 (When::TM::Calendar, When::TM::CalendarEra)

    • epoch 暦元 (Integer)

    • reverse 暦年の順序 (Boolean)

      [ false, nil 昇順 ]
      [ true       降順 ]
      
    • go back 参照イベントより前の暦日か(Boolean)

      [ false, nil 否   ]
      [ true       然り ]
      


1042
1043
1044
1045
1046
1047
# File 'lib/when_exe/inspect.rb', line 1042

def calendar_name
  void, epoch, reverse, back = @calendar_era_props
  name = [@calendar_era || @frame, epoch, reverse, back]
  name.pop until name[-1]
  return name
end

#ceil(digit = DAY, precision = digit) ⇒ When::TM::CalDate

下位桁の切り上げ

Parameters:

  • digit (Integer) (defaults to: DAY)

    切り上げずに残す、最下位の桁

  • precision (Integer) (defaults to: digit)

    切り上げ結果の分解能

Returns:



1826
1827
1828
# File 'lib/when_exe/tmposition.rb', line 1826

def ceil(digit=DAY, precision=digit)
  (self + PeriodDuration.new(1, digit, (-@frame.indices.length)..0)).floor(digit, precision)
end

#clockObject

時法の取得 - ダミー



1669
1670
1671
# File 'lib/when_exe/tmposition.rb', line 1669

def clock
  nil
end

#coordinateNumeric

時間座標値

Returns:

  • (Numeric)

    オブジェクトの precision に対応する時間座標の値

Raises:

  • (ArgumentError)


1065
1066
1067
1068
# File 'lib/when_exe/inspect.rb', line 1065

def coordinate
  raise ArgumentError, "Presicion not defined" unless When::Coordinates::PERIOD_NAME[@precision]
  self[@precision]
end

#cwdayNumeric

七曜(暦週)

Returns:

  • (Numeric)

    自身の「七曜」(月曜 1 始まり)



1184
1185
1186
# File 'lib/when_exe/inspect.rb', line 1184

def cwday
  (to_i  % 7) + 1
end

#cweek(d = 0) ⇒ Numeric

暦週

Parameters:

  • d (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示(大きいほうに位置をずらす)

Returns:

  • (Numeric)

    自身の「暦週」

Raises:

  • (IndexError)


1194
1195
1196
1197
1198
1199
1200
# File 'lib/when_exe/inspect.rb', line 1194

def cweek(d=0)
  [1,0,-1].each do |i|
    start = ((self + PeriodDuration.new(i, YEAR-d)).floor(YEAR-d,DAY) + PeriodDuration.new(4, DAY)) & Residue.new(0,7,-1)
    return ((to_i - start.to_i).div 7) + 1 if self >= start
  end
  raise IndexError, 'Cannot decide year number'
end

#cwyear(d = 0) ⇒ Numeric

暦週の年

Parameters:

  • d (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示(大きいほうに位置をずらす)

Returns:

  • (Numeric)

    自身の「暦週の年」

Raises:

  • (IndexError)


1270
1271
1272
1273
1274
1275
1276
# File 'lib/when_exe/inspect.rb', line 1270

def cwyear(d=0)
  [1,0,-1].each do |i|
    start = ((self + PeriodDuration.new(i, YEAR-d)).floor(YEAR-d,DAY) + PeriodDuration.new(4, DAY)) & Residue.new(0,7,-1)
    return year(d)+i if self >= start
  end
  raise IndexError, 'Cannot decide year number'
end

#day(d = 0) ⇒ Numeric

Parameters:

  • d (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示(大きいほうに位置をずらす)

Returns:



1148
1149
1150
# File 'lib/when_exe/inspect.rb', line 1148

def day(d=0)
  @cal_date[DAY-1-d]
end

#floor(digit = DAY, precision = digit) ⇒ When::TM::CalDate

下位桁の切り捨て

Parameters:

  • digit (Integer) (defaults to: DAY)

    切り捨てずに残す、最下位の桁

  • precision (Integer) (defaults to: digit)

    切り捨て結果の分解能

Returns:



1812
1813
1814
1815
1816
# File 'lib/when_exe/tmposition.rb', line 1812

def floor(digit=DAY, precision=digit)
  options = {:date=>@cal_date[0..(digit-1)], :events=>nil, :query=>nil}
  options[:precision] = precision if precision
  self.dup._copy(options)
end

#leaf?Boolean

暦年代が末端の参照であるか?

Returns:

  • (Boolean)


1854
1855
1856
# File 'lib/when_exe/tmposition.rb', line 1854

def leaf?
  ! @calendar_era.respond_to?(:_pool) || @calendar_era.leaf?
end

#least_significant_coordinateNumeric

最下位の要素

Returns:

  • (Numeric)

    剰余類の演算に用いる日の通し番号を返す



1751
1752
1753
# File 'lib/when_exe/tmposition.rb', line 1751

def least_significant_coordinate
  return to_i + @frame.indices[-1].shift
end

#length(upper, lower = DAY) ⇒ Integer

要素数 ― 上位要素に含まれる下位要素の数

Parameters:

  • upper (Integer)

    上位要素のインデックス

  • lower (Integer) (defaults to: DAY)

    下位要素のインデックス(DAY または MONTH)

Returns:

  • (Integer)


1837
1838
1839
1840
1841
# File 'lib/when_exe/tmposition.rb', line 1837

def length(upper, lower=DAY)
  range = [floor(upper).to_i, ceil(upper).to_i]
  range = range.map {|d| (Residue.mod(d) {|m| frame._new_month(m)})[0]} if lower == MONTH
  range[1] - range[0]
end

#mday(d = 0) ⇒ Numeric

月内通日

Parameters:

  • d (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示(大きいほうに位置をずらす)

Returns:

  • (Numeric)

    自身の「月内通日」(1始まり)



1158
1159
1160
# File 'lib/when_exe/inspect.rb', line 1158

def mday(d=0)
  to_i - floor(MONTH-d).to_i + 1
end

#memberArray<When::TM::CalDate>

Note:

precision が 0(When::DAY) の場合、空 Array を返す

自身に所属する When::TM::CalDate オブジェクト

Returns:

Raises:

  • (ArgumentError)


1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
# File 'lib/when_exe/inspect.rb', line 1077

def member
  raise ArgumentError, "Presicion not defined" unless When::Coordinates::PERIOD_NAME[@precision]
  child = floor(@precision+1)
  list  = []
  while self == child
    list << child
    child = child.succ
  end
  list
end

#month(d = 0) ⇒ Numeric Also known as: mon

Parameters:

  • d (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示(大きいほうに位置をずらす)

Returns:



1233
1234
1235
# File 'lib/when_exe/inspect.rb', line 1233

def month(d=0)
  @cal_date[MONTH-1-d]
end

#most_significant_coordinateNumeric

最上位の要素

Returns:

  • (Numeric)

    暦年代の epoch に関わらず暦法に従った年の通し番号を返す



1737
1738
1739
1740
1741
1742
1743
1744
# File 'lib/when_exe/tmposition.rb', line 1737

def most_significant_coordinate
  coordinate  = @cal_date[0]
  coordinate += calendar_era_epoch if @calendar_era_props
  @frame.index_of_MSC.times do |i|
    coordinate = +coordinate * @frame.indices[i].unit + @cal_date[i+1] - @frame.indices[i].base
  end
  coordinate
end

#mweek(w = 6, m = 7, d = 0) ⇒ Numeric

月内通週

Parameters:

  • w (Integer) (defaults to: 6)

    週の最初の曜日(0:月,.., 6:日)

  • m (Integer) (defaults to: 7)

    一週間の日数

  • d (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示(大きいほうに位置をずらす)

Returns:

  • (Numeric)

    自身の「月内通週」(その月に完全に含まれる最初の週を1とする)



1210
1211
1212
# File 'lib/when_exe/inspect.rb', line 1210

def mweek(w=6, m=7, d=0)
  1 + (to_i - (floor(MONTH-d,DAY) & Residue.new(w,m)).to_i).div(7)
end

#name(index, format = nil) ⇒ When::BasicTypes::M17n

要素の多言語対応文字列化

Parameters:

  • index (Integer)

    多言語対応文字列化する要素の指定

  • format (When::BasicTypes::M17n) (defaults to: nil)

    多言語対応文字列化の書式

Returns:



1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/when_exe/inspect.rb', line 1125

def name(index, format=nil)
  digit      = _digit(index) {|digit| digit <= DAY}
  coordinate = @cal_date[digit-1]
  return m17n(format % coordinate) if format

  indices = @frame.indices[digit-1]
  if indices
    trunk  = indices.trunk
    branch = indices.branch
  end
  format = branch ? m17n("%02d-") : "%02d"
  return m17n(format % coordinate) unless trunk
  trunk  = trunk[coordinate * 1]
  return m17n(trunk) unless branch
  return trunk.prefix(branch[coordinate * 0||0])
end

#rdf_graph(options = {}) ⇒ Hash

自身を root とするグラフの jsonld を表現する Hash を生成する

Parameters:

  • options (Hash) (defaults to: {})

    Parts::Resource.rdf_graph を参照

Returns:

  • (Hash)

    jsonld を表現する Hash



470
471
472
473
# File 'lib/when_exe/linkeddata.rb', line 470

def rdf_graph(options={})
  root = options[:include] && precision < When::YEAR ? floor(When::YEAR) : self
  When::Parts::Resource.rdf_graph([root], options)
end

#reference_labelWhen::BasicTypes::M17n

参照ラベル



1054
1055
1056
1057
1058
# File 'lib/when_exe/inspect.rb', line 1054

def reference_label
  return @calendar_era.hierarchy.map {|e| e.label} if @calendar_era
  return [@frame.label] if @frame.label
  [When::BasicTypes::M17n.new(@frame.class.to_s.split(/::/)[-1])]
end

#register_graph(graph, options = {}) ⇒ Array

CalDateオブジェクトの jsonld をグラフに追加する

Parameters:

  • graph (Array<Hash>)

    個別のCalDateオブジェクトの jsonld hash の Array

  • options (Hash) (defaults to: {})

    Parts::Resource.rdf_graph を参照

Returns:

  • (Array)

    jsonld hash の Array



482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/when_exe/linkeddata.rb', line 482

def register_graph(graph, options={})
  jsonld_hash = to_jsonld_hash(options)
  graph << jsonld_hash
  if options[:include] && precision < When::DAY
    included = floor(precision+1)
    included_opt  = {:included=>jsonld_hash['@id']}.update(options)
    while include?(included) do
      included.register_graph(graph, included_opt)
      included = included.succ
    end
  end
end

#to_iInteger

ユリウス日

Returns:

  • (Integer)

    -4712-01-01からの経過日数に対応する通番



1691
1692
1693
# File 'lib/when_exe/tmposition.rb', line 1691

def to_i
  @sdn ||= _to_i
end

#to_jsonld_hash(options = {}) ⇒ Hash

Note:

:prev,:succ,:included が true のときは自身で当該IRIを計算する。 nil,false のときは当該情報を戻り値のHashに追加しない。

CalDateオブジェクトの jsonld を表現する Hash を生成する

Parameters:

  • options (Hash) (defaults to: {})

    以下の通り

Options Hash (options):

  • :prefixes (Hash)

    Linked Data 用 namespace URI の Array の Hash (‘@context’互換でも可)

  • :context (Boolean)

    true なら 可能な限り namespace を prefix に変換する

  • :prev (String or Boolean)

    ひとつ前のCalDateオブジェクトのIRI

  • :succ (String or Boolean)

    ひとつ後のCalDateオブジェクトのIRI

  • :included (String or Boolean)

    自身を含む分解能が1低いCalDateオブジェクトのIRI

  • :note (Hash)

    暦注計算のオプション Parts::Resource#notes を参照

  • @... (Object)

    そのまま戻り値のHashに反映

Returns:

  • (Hash)

    jsonld を表現する Hash



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'lib/when_exe/linkeddata.rb', line 511

def to_jsonld_hash(options={})
  hash, context, base = hash_and_variables(options)
  tp   = base + 'tp/'
  ts   = base + 'ts#'
  hash['@id'] ||= tp + to_uri_escape
  hash[ts + 'sdn'] = precision <= When::DAY ? to_i : to_f
  hash[ts + 'frame'] = {'@id'=>frame.iri(false)}
  hash[ts + 'calendarEra'] = {'@id'=>calendar_era.iri(false)} if calendar_era
  hash[ts + 'coordinate'] = self[precision].to_s
  hash[ts + 'ruler'] = {'@id'=>query['name'].iri} if query && query['name'].kind_of?(When::BasicTypes::M17n)
  hash[ts + 'succ'] = options[:succ].kind_of?(String) ?
    options[:succ] : {'@id'=>tp + succ.to_uri_escape} if options[:succ]
  hash[ts + 'prev'] = options[:prev].kind_of?(String) ?
    options[:prev] : {'@id'=>tp + prev.to_uri_escape} if options[:prev]
  hash['@reverse'] = (hash['@reverse'] || {}).merge(
    {RDFS + 'member'=>
      {'@id'=>options[:included].kind_of?(String) ?
                options[:included] :
                tp + floor(precision-1).to_uri_escape
      }
    }) if options[:included] && precision + frame.indices.size > 0
  compact_predicate(hash, context, options[:prefixes])
  note_options = {:indices=>precision, :notes=>:all}
  note_options.update(options[:note]) if options[:note]
  notes(note_options).first.each do |note|
    next unless note[:note]
    if note[:value].kind_of?(Array)
      value = note[:value].flatten.reject {|v| v.kind_of?(Hash) || v =~ /-\z/ }.map {|v| _value_str(note[:note], v)}
      value = value.first if value.size == 1
    else
      value =_value_str(note[:note], note[:value])
    end
    id    = compact_namespace_to_prefix(value, options[:prefixes], context)
    hash[compact_namespace_to_prefix(_note_str(note[:note]), options[:prefixes], context)] = (id == value && id !~ /:\/\//) ? id : {'@id'=>id}
  end
  hash
end

#to_linked_data(writer = :jsonld, options = {}) ⇒ String

自身を root とするグラフの jsonld を表現する Hash を各種のRDF表現形式に変換する

Parameters:

  • writer (Symbol) (defaults to: :jsonld)

    RDF表現形式 (デフォルト :jsonld - 単に Hash を JSON化)

  • options (Hash) (defaults to: {})

    内部で呼び出す #to_jsonld_hash にそのまま渡す。ただし、

Options Hash (options):

  • :include (Boolean)

    自身が含む分解能が高いCalDateオブジェクトをグラフに含める(デフォルト true)

Returns:

  • (String)

    writer で指定されたRDF表現形式の文字列



459
460
461
462
# File 'lib/when_exe/linkeddata.rb', line 459

def to_linked_data(writer=:jsonld, options={})
  hash = rdf_graph({:include=>true}.update(options))
  When::Parts::Resource.to_linked_data(hash, writer, hash['@context'])
end

#to_m17n(precision = @precision, round = false) ⇒ When::BasicTypes::M17n

多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する

Parameters:

  • precision (Integer) (defaults to: @precision)

    どの桁まで多言語対応文字列化するか、分解能で指定する

  • round (false) (defaults to: false)

    常に切り捨てる(DateAndTimeとの互換性のためのダミーの引数)

Returns:



1285
1286
1287
1288
1289
1290
1291
# File 'lib/when_exe/inspect.rb', line 1285

def to_m17n(precision=@precision, round=false)
  date = m17n(_date_to_s(precision))
  return date unless @calendar_era
  return _parent_labels.inject(m17n(calendar_era_name)) {|era_name, parent|
    era_name.prefix(m17n(parent) + '::')
  } + date
end

#to_residue(remainder, divisor) ⇒ When::Coordinates::Residue

剰余類化

Parameters:

  • remainder (Numeric)

    剰余

  • divisor (Integer)

    法(>0)

Returns:



1717
1718
1719
1720
# File 'lib/when_exe/tmposition.rb', line 1717

def to_residue(remainder, divisor)
  When::Coordinates::Residue.new(remainder, divisor, {'day'  => least_significant_coordinate,
                                                      'year' => most_significant_coordinate})
end

#to_s(precision = @precision, round = false) ⇒ String

文字列化 - When.exe Standard Representation により文字列化する

Parameters:

  • precision (Integer) (defaults to: @precision)

    どの桁まで多言語対応文字列化するか、分解能で指定する

  • round (false) (defaults to: false)

    常に切り捨てる(DateAndTimeとの互換性のためのダミーの引数)

Returns:



1300
1301
1302
1303
1304
1305
1306
# File 'lib/when_exe/inspect.rb', line 1300

def to_s(precision=@precision, round=false)
  date = _date_to_s(precision)
  return date unless @calendar_era
  return _parent_labels.inject(calendar_era_name.to_s) {|era_name, parent|
    parent.to_s + '::' + era_name
  } + date
end

#to_uri_linkeddataString

URI - linked data 用

Returns:



444
445
446
447
448
449
# File 'lib/when_exe/linkeddata.rb', line 444

def to_uri_linkeddata(*args)
  date, frame = _to_uri(to_s(*args)).split('^^', 2)
  frame += '_' if frame =~ /\d\z/
  date = "#{frame}(#{date})" if frame
  When::Parts::Resource.base_uri.sub(/When\/$/, 'tp/') + date
end

#universal_timeNumeric Also known as: local_time

内部時間

Returns:

  • (Numeric)

    当日正午の 1970-01-01T00:00:00Z からの Universal Coordinated Time の経過時間 / 128秒



1679
1680
1681
1682
# File 'lib/when_exe/tmposition.rb', line 1679

def universal_time
  return super if [Now, Max, Min].include?(@indeterminated_position)
  @universal_time ||= JulianDate._d_to_t(to_i)
end

#value(index) ⇒ Numeric

要素の参照

Parameters:

  • index (Integer, String)

    参照する要素の指定

Returns:



1728
1729
1730
# File 'lib/when_exe/tmposition.rb', line 1728

def value(index)
  @cal_date[(_digit(index) {|digit| digit <= DAY})-1]
end

#wdayNumeric

七曜

Returns:

  • (Numeric)

    自身の「七曜」(日曜 0 始まり)



1176
1177
1178
# File 'lib/when_exe/inspect.rb', line 1176

def wday
  (to_i + 1) % 7
end

#yday(d = 0) ⇒ Numeric

年内通日

Parameters:

  • d (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示(大きいほうに位置をずらす)

Returns:

  • (Numeric)

    自身の「年内通日」(1始まり)



1168
1169
1170
# File 'lib/when_exe/inspect.rb', line 1168

def yday(d=0)
  to_i - floor(YEAR-d).to_i + 1
end

#year(d = 0) ⇒ Numeric

Parameters:

  • d (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示(大きいほうに位置をずらす)

Returns:



1260
1261
1262
# File 'lib/when_exe/inspect.rb', line 1260

def year(d=0)
  @cal_date[YEAR-1-d]
end

#ymon(d1 = 0, d2 = 0) ⇒ Numeric

年内通月

Parameters:

  • d1 (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示-年用(大きいほうに位置をずらす)

  • d2 (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示-月用(大きいほうに位置をずらす)

Returns:

  • (Numeric)

    自身の「年内通月」(1始まり)

Raises:

  • (IndexError)


1245
1246
1247
1248
1249
1250
1251
1252
# File 'lib/when_exe/inspect.rb', line 1245

def ymon(d1=0, d2=0)
  current = floor(YEAR-d1, MONTH-d2)
  @frame._length(@cal_date[(YEAR-1-d1)...(MONTH-1-d2)]).times do |i|
    return i+1 if current == self
    current = current.succ
  end
  raise IndexError, 'Cannot decide month number'
end

#yweek(w = 6, m = 7, d = 0) ⇒ Numeric

年内通週

Parameters:

  • w (Integer) (defaults to: 6)

    週の最初の曜日(0:月,.., 6:日)

  • m (Integer) (defaults to: 7)

    一週間の日数

  • d (Integer) (defaults to: 0)

    日付が‘年月日’でない表現のための桁位置変更指示(大きいほうに位置をずらす)

Returns:

  • (Numeric)

    自身の「年内通週」(その年に完全に含まれる最初の週を1とする)



1223
1224
1225
# File 'lib/when_exe/inspect.rb', line 1223

def yweek(w=6, m=7, d=0)
  1 + (to_i - (floor(YEAR-d,DAY) & Residue.new(w,m)).to_i).div(7)
end