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.
Class Method Summary collapse
-
.options ⇒ Object
JSON-LD Reader options.
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.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/json/ld/reader.rb', line 62 def initialize(input = $stdin, **, &block) [:base_uri] ||= [: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 |
Class Method Details
.options ⇒ Object
JSON-LD Reader options
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/json/ld/reader.rb', line 15 def self. 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: :extractAllScripts, datatype: TrueClass, default: false, control: :checkbox, on: ["--[no-]extract-all-scripts"], description: "If set to true, when extracting JSON-LD script elements from HTML, unless a specific fragment identifier is targeted, extracts all encountered JSON-LD script elements using an array form, if necessary.") {|arg| RDF::URI(arg)}, RDF::CLI::Option.new( symbol: :lowercaseLanguage, datatype: TrueClass, control: :checkbox, on: ["--[no-]lowercase-language"], description: "By default, language tags are left as is. To normalize to lowercase, set this option to `true`."), RDF::CLI::Option.new( symbol: :processingMode, 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)"), RDF::CLI::Option.new( symbol: :rdfDirection, datatype: %w(i18n-datatype compound-literal), default: 'null', control: :select, on: ["--rdf-direction DIR", %w(i18n-datatype compound-literal)], description: "How to serialize literal direction (i18n-datatype compound-literal)") {|arg| RDF::URI(arg)}, ] end |
Instance Method Details
#each_statement(&block) ⇒ Object
87 88 89 90 91 |
# File 'lib/json/ld/reader.rb', line 87 def each_statement(&block) JSON::LD::API.toRdf(@doc, **@options, &block) rescue ::JSON::ParserError, ::JSON::LD::JsonLdError => e log_fatal("Failed to parse input document: #{e.}", exception: RDF::ReaderError) end |