Class: Ldp::Resource::RdfSource

Inherits:
Ldp::Resource show all
Defined in:
lib/ldp/resource/rdf_source.rb

Direct Known Subclasses

Container

Instance Attribute Summary

Attributes inherited from Ldp::Resource

#client, #subject

Instance Method Summary collapse

Methods inherited from Ldp::Resource

#current?, #delete, for, #get, #head, #new?, #reload, #retrieved_content?, #save, #subject_uri, #update, #update_cached_get

Constructor Details

#initialize(client, subject, graph_or_response = nil, base_path = '') ⇒ RdfSource

Returns a new instance of RdfSource.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ldp/resource/rdf_source.rb', line 5

def initialize client, subject, graph_or_response = nil, base_path = ''
  super

  case graph_or_response
    when RDF::Enumerable
      @graph = graph_or_response
    when Ldp::Response
    when NilClass
      #nop
    else
      raise ArgumentError, "Third argument to #{self.class}.new should be a RDF::Enumerable or a Ldp::Response. You provided #{graph_or_response.class}"
  end
end

Instance Method Details

#bodyObject

Get the body and ensure it’s UTF-8 encoded. Since Fedora 9.3 isn’t returning a charset, then Net::HTTP is just returning ASCII-8BIT See github.com/ruby-rdf/rdf-turtle/issues/13 See jira.duraspace.org/browse/FCREPO-1750



56
57
58
# File 'lib/ldp/resource/rdf_source.rb', line 56

def body
  body.force_encoding('utf-8')
end

#build_empty_graphObject



33
34
35
# File 'lib/ldp/resource/rdf_source.rb', line 33

def build_empty_graph
  graph_class.new
end

#contentObject



25
26
27
# File 'lib/ldp/resource/rdf_source.rb', line 25

def content
  graph.dump(:ttl) if graph
end

#createObject



19
20
21
22
23
# File 'lib/ldp/resource/rdf_source.rb', line 19

def create
  super do |req|
    req.headers["Content-Type"] = "text/turtle"
  end
end

#graphObject



29
30
31
# File 'lib/ldp/resource/rdf_source.rb', line 29

def graph
  @graph ||= new? ? build_empty_graph : filtered_graph(response_graph)
end

#graph_classClass

graph_class may be overridden so that a subclass of RDF::Graph is returned (e.g. an ActiveTriples resource)

Returns:

  • (Class)

    a class that is an descendant of RDF::Graph



41
42
43
# File 'lib/ldp/resource/rdf_source.rb', line 41

def graph_class
  RDF::Graph
end

#response_graphRDF::Graph

Parse the graph returned by the LDP server into an RDF::Graph

Returns:

  • (RDF::Graph)


48
49
50
# File 'lib/ldp/resource/rdf_source.rb', line 48

def response_graph
  @response_graph ||= response_as_graph(get)
end