Class: Triannon::Annotation
- Inherits:
-
Object
- Object
- Triannon::Annotation
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/triannon/annotation.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#expected_content_type ⇒ Object
Returns the value of attribute expected_content_type.
-
#id ⇒ Object
Returns the value of attribute id.
-
#root_container ⇒ Object
Returns the value of attribute root_container.
Class Method Summary collapse
-
.create(attrs = {}) ⇒ Object
Class Methods —————————————————————-.
- .find(root_container, id) ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
- #graph ⇒ Object
- #graph=(g) ⇒ Object
-
#id_as_url ⇒ String
The id of this annotation as a url or nil if no graph.
-
#jsonld_iiif ⇒ Object
Json-ld representation of anno with IIIF context as a url.
-
#jsonld_oa ⇒ Object
Json-ld representation of anno with OpenAnnotation context as a url.
-
#motivated_by ⇒ Array<String>
Of urls expressing the OA motivated_by values or nil if no graph.
- #persisted? ⇒ Boolean
-
#save ⇒ Object
Instance Methods —————————————————————-.
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
9 10 11 |
# File 'app/models/triannon/annotation.rb', line 9 def data @data end |
#expected_content_type ⇒ Object
Returns the value of attribute expected_content_type.
9 10 11 |
# File 'app/models/triannon/annotation.rb', line 9 def expected_content_type @expected_content_type end |
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'app/models/triannon/annotation.rb', line 9 def id @id end |
#root_container ⇒ Object
Returns the value of attribute root_container.
9 10 11 |
# File 'app/models/triannon/annotation.rb', line 9 def root_container @root_container end |
Class Method Details
.create(attrs = {}) ⇒ Object
Class Methods —————————————————————-
23 24 25 26 27 |
# File 'app/models/triannon/annotation.rb', line 23 def self.create(attrs = {}) a = Triannon::Annotation.new attrs a.save a end |
.find(root_container, id) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'app/models/triannon/annotation.rb', line 31 def self.find(root_container, id) oa_graph = Triannon::LdpLoader.load(root_container, id) anno = Triannon::Annotation.new anno.graph = oa_graph anno.id = id anno.root_container = root_container anno end |
Instance Method Details
#destroy ⇒ Object
53 54 55 56 57 |
# File 'app/models/triannon/annotation.rb', line 53 def destroy run_callbacks :destroy do Triannon::LdpWriter.delete_anno "#{root_container}/#{id}" end end |
#graph ⇒ Object
63 64 65 66 67 68 |
# File 'app/models/triannon/annotation.rb', line 63 def graph @graph ||= begin g = data_to_graph OA::Graph.new g if g.kind_of? RDF::Graph end end |
#graph=(g) ⇒ Object
71 72 73 74 75 76 77 |
# File 'app/models/triannon/annotation.rb', line 71 def graph= g if g.is_a? OA::Graph @graph = g elsif g.kind_of? RDF::Graph @graph = OA::Graph.new g end end |
#id_as_url ⇒ String
Returns the id of this annotation as a url or nil if no graph.
90 91 92 |
# File 'app/models/triannon/annotation.rb', line 90 def id_as_url graph.id_as_url if graph_exists? end |
#jsonld_iiif ⇒ Object
Returns json-ld representation of anno with IIIF context as a url.
85 86 87 |
# File 'app/models/triannon/annotation.rb', line 85 def jsonld_iiif graph.jsonld_iiif end |
#jsonld_oa ⇒ Object
Returns json-ld representation of anno with OpenAnnotation context as a url.
80 81 82 |
# File 'app/models/triannon/annotation.rb', line 80 def jsonld_oa graph.jsonld_oa end |
#motivated_by ⇒ Array<String>
Returns of urls expressing the OA motivated_by values or nil if no graph.
95 96 97 |
# File 'app/models/triannon/annotation.rb', line 95 def motivated_by graph.motivated_by if graph_exists? end |
#persisted? ⇒ Boolean
59 60 61 |
# File 'app/models/triannon/annotation.rb', line 59 def persisted? id.present? end |
#save ⇒ Object
Instance Methods —————————————————————-
42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/triannon/annotation.rb', line 42 def save run_callbacks :save do # TODO: check if valid anno? @id = Triannon::LdpWriter.create_anno(self, root_container) if graph && graph.size > 2 # reload from storage to get the anno id within the graph # TODO: do graph manipulation to add id instead? @graph = Triannon::LdpLoader.load(root_container, id) id end end |