Class: RDF::Serializers::HndJSONParser

Inherits:
Object
  • Object
show all
Includes:
DataTypeHelper
Defined in:
lib/rdf/serializers/hdnjson_parser.rb

Constant Summary collapse

HEX_SUBJECT =
0
HEX_PREDICATE =
1
HEX_OBJECT =
2
HEX_DATATYPE =
3
HEX_LANGUAGE =
4
HEX_GRAPH =
5

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DataTypeHelper

#xsd_to_rdf

Class Method Details

.parse(body) ⇒ Object



64
65
66
# File 'lib/rdf/serializers/hdnjson_parser.rb', line 64

def parse(body)
  new.parse_body(body)
end

Instance Method Details

#parse_body(body) ⇒ Object



15
16
17
# File 'lib/rdf/serializers/hdnjson_parser.rb', line 15

def parse_body(body)
  body.split("\n").map { |line| parse_hex(JSON.parse(line)) }
end

#parse_hex(hex) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rdf/serializers/hdnjson_parser.rb', line 19

def parse_hex(hex)
  subject = parse_subject(hex[HEX_SUBJECT])
  predicate = RDF::URI(hex[HEX_PREDICATE])
  object = parse_object(hex[HEX_OBJECT], hex[HEX_DATATYPE], hex[HEX_LANGUAGE])
  graph = hex[HEX_GRAPH].present? ? RDF::URI(hex[HEX_GRAPH]) : RDF::Serializers.config.default_graph

  RDF::Statement.new(
    subject,
    predicate,
    object,
    graph_name: graph
  )
end