Class: RDF::Tabular::JSON

Inherits:
Literal
  • Object
show all
Defined in:
lib/rdf/tabular/literal.rb

Overview

A JSON literal.

Constant Summary collapse

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

Instance Method Summary collapse

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 '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:

  • (Object)


30
31
32
# File 'lib/rdf/tabular/literal.rb', line 30

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

#to_sObject



34
35
36
# File 'lib/rdf/tabular/literal.rb', line 34

def to_s
  @string ||= value.to_json
end