Class: RDF::Tabular::JSON

Inherits:
Literal show all
Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/rdf-tabular-6243d85fc308/lib/rdf/tabular/literal.rb

Overview

A JSON literal.

Constant Summary

DATATYPE =
RDF::Tabular::CSVW.json
GRAMMAR =
nil

Constants inherited from Literal

Literal::FALSE, Literal::TRUE, Literal::ZERO

Instance Attribute Summary

Attributes inherited from Literal

#datatype, #language

Instance Method Summary collapse

Methods inherited from Literal

#==, #canonicalize!, #compatible?, #comperable_datatype?, #eql?, #escape, #has_datatype?, #has_language?, #hash, #humanize, #inspect, #literal?, #method_missing, #plain?, #respond_to_missing?, #simple?, #squish, #squish!, #valid?, #validate!, #value, #value_hash

Methods included from RDF::Term

#<=>, #==, #aggregate?, #compatible?, #eql?, #escape, #evaluate, #ndvars, #term?, #to_base, #to_term, #vars

Methods included from SPARQL::Algebra::Expression

cast, #constant?, #evaluate, extension, extensions, for, #invalid?, new, #node?, open, #optimize, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?

Methods included from Value

#anonymous?, #canonicalize, #canonicalize!, #constant?, #graph?, #inspect, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #start_with?, #statement?, #term?, #to_nquads, #to_ntriples, #to_rdf, #to_term, #type_error, #uri?, #valid?, #validate!, #variable?

Constructor Details

#initialize(value, options = {}) ⇒ JSON

Returns a new instance of JSON

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :lexical (String) — default: nil


16
17
18
19
20
21
22
23
24
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-tabular-6243d85fc308/lib/rdf/tabular/literal.rb', line 16

def initialize(value, options = {})
  @datatype = options[:datatype] || DATATYPE
  @string   = options[:lexical] if options.has_key?(:lexical)
  if value.is_a?(String)
    @string ||= value
  else
    @object = value
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Literal

Instance Method Details

#objectObject

Parse value, if necessary

Returns:



30
31
32
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-tabular-6243d85fc308/lib/rdf/tabular/literal.rb', line 30

def object
  @object ||= ::JSON.parse(value)
end

#to_sObject



34
35
36
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-tabular-6243d85fc308/lib/rdf/tabular/literal.rb', line 34

def to_s
  @string ||= value.to_json
end