Method: JSON::LD::API#initialize
- Defined in:
- lib/json/ld/api.rb
#initialize(input, context, options = {}) {|api| ... } ⇒ API
Initialize the API, reading in any document and setting global options
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/json/ld/api.rb', line 77 def initialize(input, context, = {}, &block) = {:compactArrays => true}.merge() [:validate] = true if [:processingMode] == "json-ld-1.0" [:documentLoader] ||= self.class.method(:documentLoader) [:rename_bnodes] ||= true @namer = [:rename_bnodes] ? BlankNodeNamer.new("b") : BlankNodeMapper.new @value = case input when Array, Hash then input.dup when IO, StringIO = {:base => input.base_uri}.merge() if input.respond_to?(:base_uri) JSON.parse(input.read) when String remote_doc = [:documentLoader].call(input, ) = {:base => remote_doc.documentUrl}.merge() context = context ? [context, remote_doc.contextUrl].compact : remote_doc.contextUrl case remote_doc.document when String then JSON.parse(remote_doc.document) else remote_doc.document end end # Update calling context :base option, if not defined [:base] ||= [:base] if [:base] @context = Context.new() @context = @context.parse(context) if context if block_given? case block.arity when 0, -1 then instance_eval(&block) else block.call(self) end end end |