Method: When::TM::CalDate#to_jsonld_hash

Defined in:
lib/when_exe/linkeddata.rb

#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



544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/when_exe/linkeddata.rb', line 544

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