Class: JSON::LD::Reader
- Inherits:
-
RDF::Reader
- Object
- RDF::Reader
- JSON::LD::Reader
- Defined in:
- lib/json/ld/reader.rb
Overview
A JSON-LD parser in Ruby.
Defined Under Namespace
Classes: EvaluationContext
Instance Attribute Summary collapse
-
#graph ⇒ RDF::Graph
readonly
The graph constructed when parsing.
Instance Method Summary collapse
- #each_statement(&block) ⇒ Object
- #each_triple(&block) ⇒ Object
-
#initialize(input = $stdin, options = {}) {|reader| ... } ⇒ Reader
constructor
Initializes the RDF/JSON reader instance.
Constructor Details
#initialize(input = $stdin, options = {}) {|reader| ... } ⇒ Reader
Initializes the RDF/JSON reader instance.
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/json/ld/reader.rb', line 94 def initialize(input = $stdin, = {}, &block) super do @base_uri = uri([:base_uri]) if [:base_uri] @doc = ::JSON.load(input) if block_given? case block.arity when 0 then instance_eval(&block) else block.call(self) end end end end |
Instance Attribute Details
#graph ⇒ RDF::Graph (readonly)
The graph constructed when parsing.
14 15 16 |
# File 'lib/json/ld/reader.rb', line 14 def graph @graph end |
Instance Method Details
#each_statement(&block) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/json/ld/reader.rb', line 111 def each_statement(&block) @callback = block # initialize the evaluation context with the appropriate base ec = EvaluationContext.new do |ec| ec.base = @base_uri if @base_uri parse_context(ec, DEFAULT_CONTEXT) end traverse("", @doc, nil, nil, ec) end |
#each_triple(&block) ⇒ Object
126 127 128 129 130 |
# File 'lib/json/ld/reader.rb', line 126 def each_triple(&block) each_statement do |statement| block.call(*statement.to_triple) end end |