Class: Dbd::Resource
- Inherits:
-
Object
- Object
- Dbd::Resource
- Includes:
- Helpers::OrderedSetCollection
- Defined in:
- lib/dbd/resource.rb
Overview
A Resource is a collection of facts that have the same subject.
In the real-world this is a mainly an "instance" about which all facts are giving information (e.g. a conference, a person, a bicycle, ...). More generally this can also be used to describe classes and other concepts in the software system.
A new (random) subject is generated for a resource. In Dbd, a subject is a random uuid (like a oid), not a meaningful URI as it is in RDF.
A provenance_subject is a required field in the options hash. Practically, first a ProvenanceResource will be created and the subject of that will be used as provenance_subject for the Resources that are associated with it.
During build-up of a Fact, the subject and the provenance_subject can be nil. These will then be set when the Fact is added (with '<<') to a resource.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Class Method Summary collapse
-
.new_subject ⇒ Fact::Subject
A new (random) Resource subject.
Instance Method Summary collapse
-
#<<(fact) ⇒ Object
Add a fact.
-
#initialize(options) ⇒ Resource
constructor
Build a new resource.
-
#provenance_subject ⇒ Object
Getter for provenance_subject.
Methods included from Helpers::OrderedSetCollection
add_and_return_index, #each, #last, #size
Constructor Details
#initialize(options) ⇒ Resource
Build a new resource.
By default, a new (random) subject is generated for a resource. Optionally, an explicit subject can be given in the options parameter (this is best created with the new_subject class method for forward compatibility).
The provenance_subject argument is required. This will typically be taken from an earlier created ProvenanceResource.
57 58 59 60 61 62 |
# File 'lib/dbd/resource.rb', line 57 def initialize() @subject = [:subject] || self.class.new_subject @provenance_subject = [:provenance_subject] validate_provenance_subject super() end |
Instance Attribute Details
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
28 29 30 |
# File 'lib/dbd/resource.rb', line 28 def subject @subject end |
Class Method Details
.new_subject ⇒ Fact::Subject
Returns a new (random) Resource subject.
40 41 42 |
# File 'lib/dbd/resource.rb', line 40 def self.new_subject Fact.new_subject end |
Instance Method Details
#<<(fact) ⇒ Object
Add a fact.
- if it has no subject, the subject is set (this modifies the fact !)
- if is has the same subject as the resource, added unchanged.
- if it has a different subject, a SubjectError is raised.
- if it has no provenance_subject, the provenance_subject is set (this modifies the fact !)
- if is has the same provenance_subject as the resource, added unchanged.
- if it has a different provenance_subject, a ProvenanceError is raised.
73 74 75 76 77 78 |
# File 'lib/dbd/resource.rb', line 73 def <<(fact) # TODO: check the type of the fact (Fact) set_subject!(fact) set_provenance!(fact) super(fact) end |
#provenance_subject ⇒ Object
Getter for provenance_subject.
Will be overridden in the ProvenanceResource subclass.
34 35 36 |
# File 'lib/dbd/resource.rb', line 34 def provenance_subject @provenance_subject end |