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 を生成する
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(={}) 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 |