Class: Tripod::ResourceCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tripod/resource_collection.rb

Overview

 class that wraps a collection of resources, and allows them to be serialized

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resources) ⇒ ResourceCollection

Returns a new instance of ResourceCollection.



12
13
14
# File 'lib/tripod/resource_collection.rb', line 12

def initialize(resources)
  @resources = resources
end

Instance Attribute Details

#resourcesObject (readonly)

Returns the value of attribute resources.



10
11
12
# File 'lib/tripod/resource_collection.rb', line 10

def resources
  @resources
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
# File 'lib/tripod/resource_collection.rb', line 34

def ==(other)
  self.to_nt == other.to_nt
end

#[](*args) ⇒ Object

allow index operator to act on underlying array of resources.



30
31
32
# File 'lib/tripod/resource_collection.rb', line 30

def [](*args)
  resources[*args]
end

#eachObject



20
21
22
# File 'lib/tripod/resource_collection.rb', line 20

def each
  self.resources.each { |e| yield(e) }
end

#lengthObject



16
17
18
# File 'lib/tripod/resource_collection.rb', line 16

def length
  self.resources.length
end

#to_aObject

return the underlying array



25
26
27
# File 'lib/tripod/resource_collection.rb', line 25

def to_a
  resources
end

#to_json(opts = {}) ⇒ Object



47
48
49
# File 'lib/tripod/resource_collection.rb', line 47

def to_json(opts={})
  get_graph.dump(:jsonld)
end

#to_ntObject

 for n-triples we can just concatenate them



39
40
41
42
43
44
45
# File 'lib/tripod/resource_collection.rb', line 39

def to_nt
  nt = ""
  resources.each do |resource|
    nt += resource.to_nt
  end
  nt
end

#to_rdfObject



51
52
53
# File 'lib/tripod/resource_collection.rb', line 51

def to_rdf
  get_graph.dump(:rdf)
end

#to_ttlObject



55
56
57
# File 'lib/tripod/resource_collection.rb', line 55

def to_ttl
  get_graph.dump(:n3)
end