Class: RDF::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/mongo.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_mongo(statement) ⇒ Hash

Create BSON for a statement representation. Note that if the statement has no graph name, a value of false will be used to indicate the default context

Parameters:

Returns:

  • (Hash)

    Generated BSON representation of statement.



22
23
24
25
26
27
28
# File 'lib/rdf/mongo.rb', line 22

def self.from_mongo(statement)
  RDF::Statement.new(
    subject:    RDF::Mongo::Conversion.from_mongo(statement['s'], statement['st'], statement['sl']),
    predicate:  RDF::Mongo::Conversion.from_mongo(statement['p'], statement['pt'], statement['pl']),
    object:     RDF::Mongo::Conversion.from_mongo(statement['o'], statement['ot'], statement['ol']),
    graph_name: RDF::Mongo::Conversion.from_mongo(statement['c'], statement['ct'], statement['cl']))
end

Instance Method Details

#to_mongoHash

Creates a BSON representation of the statement.

Returns:

  • (Hash)


10
11
12
13
14
# File 'lib/rdf/mongo.rb', line 10

def to_mongo
  self.to_h.inject({}) do |hash, (place_in_statement, entity)|
    hash.merge(RDF::Mongo::Conversion.to_mongo(entity, place_in_statement))
  end
end