Class: Tripod::ResourceCollection
- Inherits:
-
Object
- Object
- Tripod::ResourceCollection
- 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
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#[](*args) ⇒ Object
allow index operator to act on underlying array of resources.
- #each ⇒ Object
-
#initialize(resources) ⇒ ResourceCollection
constructor
A new instance of ResourceCollection.
- #length ⇒ Object
-
#to_a ⇒ Object
return the underlying array.
- #to_json(opts = {}) ⇒ Object
-
#to_nt ⇒ Object
for n-triples we can just concatenate them.
- #to_rdf ⇒ Object
- #to_ttl ⇒ Object
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
#resources ⇒ Object (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 |
#each ⇒ Object
20 21 22 |
# File 'lib/tripod/resource_collection.rb', line 20 def each self.resources.each { |e| yield(e) } end |
#length ⇒ Object
16 17 18 |
# File 'lib/tripod/resource_collection.rb', line 16 def length self.resources.length end |
#to_a ⇒ Object
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_nt ⇒ Object
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_rdf ⇒ Object
51 52 53 |
# File 'lib/tripod/resource_collection.rb', line 51 def to_rdf get_graph.dump(:rdf) end |
#to_ttl ⇒ Object
55 56 57 |
# File 'lib/tripod/resource_collection.rb', line 55 def to_ttl get_graph.dump(:n3) end |