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 を生成する

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に反映



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