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 を生成する
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(={}) hash, context, base = hash_and_variables() 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'] = [:succ].kind_of?(String) ? [:succ] : {'@id'=>tp + succ.to_uri_escape} if [:succ] hash[ts + 'prev'] = [:prev].kind_of?(String) ? [:prev] : {'@id'=>tp + prev.to_uri_escape} if [:prev] hash['@reverse'] = (hash['@reverse'] || {}).merge( {RDFS + 'member'=> {'@id'=>[:included].kind_of?(String) ? [:included] : tp + floor(precision-1).to_uri_escape } }) if [:included] && precision + frame.indices.size > 0 compact_predicate(hash, context, [:prefixes]) = {:indices=>precision, :notes=>:all} .update([:note]) if [:note] notes().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, [:prefixes], context) hash[compact_namespace_to_prefix(_note_str(note[:note]), [:prefixes], context)] = (id == value && id !~ /:\/\//) ? id : {'@id'=>id} end hash end |