Class: RDF::Tabular::JSON

Inherits:
Literal show all
Defined in:
vendor/bundler/ruby/3.1.0/bundler/gems/rdf-tabular-c40c620313ac/lib/rdf/tabular/literal.rb

Overview

A JSON literal.

Constant Summary collapse

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

Constants inherited from Literal

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

Constants included from N3::Terminals

N3::Terminals::ANON, N3::Terminals::BASE, N3::Terminals::BLANK_NODE_LABEL, N3::Terminals::DECIMAL, N3::Terminals::DOUBLE, N3::Terminals::ECHAR, N3::Terminals::ESCAPE_CHAR4, N3::Terminals::ESCAPE_CHAR8, N3::Terminals::EXPONENT, N3::Terminals::INTEGER, N3::Terminals::IPLSTART, N3::Terminals::IRIREF, N3::Terminals::IRI_RANGE, N3::Terminals::LANGTAG, N3::Terminals::PERCENT, N3::Terminals::PLX, N3::Terminals::PNAME_LN, N3::Terminals::PNAME_NS, N3::Terminals::PN_CHARS, N3::Terminals::PN_CHARS_BASE, N3::Terminals::PN_CHARS_BODY, N3::Terminals::PN_CHARS_U, N3::Terminals::PN_LOCAL, N3::Terminals::PN_LOCAL_BODY, N3::Terminals::PN_LOCAL_ESC, N3::Terminals::PN_PREFIX, N3::Terminals::PREFIX, N3::Terminals::QUICK_VAR_NAME, N3::Terminals::STRING_LITERAL_LONG_QUOTE, N3::Terminals::STRING_LITERAL_LONG_SINGLE_QUOTE, N3::Terminals::STRING_LITERAL_QUOTE, N3::Terminals::STRING_LITERAL_SINGLE_QUOTE, N3::Terminals::UCHAR, N3::Terminals::U_CHARS1, N3::Terminals::U_CHARS2, N3::Terminals::WS

Constants included from SPARQL::Algebra::Expression

SPARQL::Algebra::Expression::PATTERN_PARENTS

Constants included from Util::Logger

Util::Logger::IOWrapper

Instance Attribute Summary

Attributes inherited from Literal

#datatype, #language

Instance Method Summary collapse

Methods inherited from Literal

#<=>, #==, #as_datetime, #as_number, #canonicalize!, #compatible?, #comperable_datatype2?, #comperable_datatype?, #datatype?, #eql?, #escape, #hash, #humanize, #inspect, #language?, #literal?, #method_missing, #plain?, #respond_to_missing?, #simple?, #squish, #squish!, #valid?, #valid_extended?, #validate!, #value, #value_hash

Methods included from RDF::Term

#<=>, #==, #aggregate?, #as_datetime, #as_number, #compatible?, #eql?, #escape, #evaluate, #ndvars, #optimize, #sameTerm?, #term?, #terms, #to_base, #to_sparql, #to_term, #vars

Methods included from SPARQL::Algebra::Expression

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

Methods included from Util::Logger

#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger

Methods included from Value

#anonymous?, #canonicalize, #canonicalize!, #constant?, #formula?, #graph?, #inspect, #inspect!, #invalid?, #iri?, #list?, #literal?, #node?, #resource?, #start_with?, #statement?, #term?, #to_ndvar, #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)

    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/3.1.0/bundler/gems/rdf-tabular-c40c620313ac/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/3.1.0/bundler/gems/rdf-tabular-c40c620313ac/lib/rdf/tabular/literal.rb', line 30

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

#to_sObject



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

def to_s
  @string ||= value.to_json
end