Class: JSON::LD::Reader

Inherits:
RDF::Reader show all
Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/json-ld-4e9cdb2fc35e/lib/json/ld/reader.rb

Overview

A JSON-LD parser in Ruby.

Direct Known Subclasses

RDF::Microdata::JsonLdReader

Instance Attribute Summary

Attributes inherited from RDF::Reader

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RDF::Reader

#base_uri, #canonicalize?, #close, each, #encoding, #fail_object, #fail_predicate, #fail_subject, for, format, #intern?, #lineno, open, #prefix, #prefixes, #prefixes=, #read_statement, #read_triple, #rewind, to_sym, #to_sym, #valid?, #validate?

Methods included from RDF::Util::Aliasing::LateBound

#alias_method

Methods included from RDF::Enumerable

add_entailment, #dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_subject, #each_term, #entail, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph_names, #has_graph?, #has_object?, #has_predicate?, #has_quad?, #has_statement?, #has_subject?, #has_term?, #has_triple?, #invalid?, #method_missing, #objects, #predicates, #project_graph, #quads, #respond_to_missing?, #statements, #subjects, #supports?, #terms, #to_a, #to_h, #to_set, #triples, #valid?, #validate!

Methods included from RDF::Isomorphic

#bijection_to, #isomorphic_with?

Methods included from RDF::Countable

#count, #empty?

Methods included from RDF::Readable

#readable?

Methods included from RDF::Util::Logger

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

Constructor Details

#initialize(input = $stdin, options = {}) {|reader| ... } ⇒ Reader

Initializes the RDF/JSON reader instance.

Parameters:

  • input (IO, File, String) (defaults to: $stdin)
  • options (Hash{Symbol => Object}) (defaults to: {})

    any additional options (see RDF::Reader#initialize and API.initialize)

Yields:

  • (reader)

    self

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Raises:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/json-ld-4e9cdb2fc35e/lib/json/ld/reader.rb', line 42

def initialize(input = $stdin, options = {}, &block)
  options[:base_uri] ||= options[:base]
  super do
    @options[:base] ||= base_uri.to_s if base_uri
    begin
      # Trim non-JSON stuff in script.
      @doc = if input.respond_to?(:read)
        input
      else
        StringIO.new(input.to_s.sub(%r(\A[^{\[]*)m, '').sub(%r([^}\]]*\Z)m, ''))
      end
    end

    if block_given?
      case block.arity
        when 0 then instance_eval(&block)
        else block.call(self)
      end
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RDF::Enumerable

Class Method Details

.optionsObject

JSON-LD Reader options



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/json-ld-4e9cdb2fc35e/lib/json/ld/reader.rb', line 15

def self.options
  super + [
    RDF::CLI::Option.new(
      symbol: :expandContext,
      control: :url2,
      datatype: RDF::URI,
      on: ["--expand-context CONTEXT"],
      description: "Context to use when expanding.") {|arg| RDF::URI(arg)},
    RDF::CLI::Option.new(
      symbol: :processing_mode,
      datatype: %w(json-ld-1.0 json-ld-1.1),
      control: :radio,
      on: ["--processingMode MODE", %w(json-ld-1.0 json-ld-1.1)],
      description: "Set Processing Mode (json-ld-1.0 or json-ld-1.1)"),
  ]
end