Class: RDF::Tabular::JSON

Inherits:
Literal show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-40be65aa0ee4/lib/rdf/tabular/literal.rb

Overview

A JSON literal.

Constant Summary collapse

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

Instance Method Summary collapse

Methods inherited from Literal

#inspect, #valid_extended?

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.5.0/bundler/gems/rdf-tabular-40be65aa0ee4/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

Instance Method Details

#objectObject

Parse value, if necessary

Returns:



30
31
32
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-tabular-40be65aa0ee4/lib/rdf/tabular/literal.rb', line 30

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

#to_sObject



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

def to_s
  @string ||= value.to_json
end