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.
Class Method Summary collapse
-
.all ⇒ Object
deprecated
Deprecated.
-
was used by old annotations#index action, before redirect to search (2015-04)
-
-
.create(attrs = {}) ⇒ Object
Class Methods —————————————————————-.
- .find(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 |
Class Method Details
.all ⇒ Object
-
was used by old annotations#index action, before redirect to search (2015-04)
39 40 41 |
# File 'app/models/triannon/annotation.rb', line 39 def self.all Triannon::LdpLoader.find_all end |
.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(id) ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/models/triannon/annotation.rb', line 30 def self.find(id) oa_graph = Triannon::LdpLoader.load id anno = Triannon::Annotation.new anno.graph = oa_graph anno.id = id anno end |
Instance Method Details
#destroy ⇒ Object
56 57 58 59 60 |
# File 'app/models/triannon/annotation.rb', line 56 def destroy _run_destroy_callbacks do Triannon::LdpWriter.delete_anno @id end end |
#graph ⇒ Object
66 67 68 69 70 71 |
# File 'app/models/triannon/annotation.rb', line 66 def graph @graph ||= begin g = data_to_graph OA::Graph.new g if g.kind_of? RDF::Graph end end |
#graph=(g) ⇒ Object
74 75 76 77 78 79 80 |
# File 'app/models/triannon/annotation.rb', line 74 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.
93 94 95 |
# File 'app/models/triannon/annotation.rb', line 93 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.
88 89 90 |
# File 'app/models/triannon/annotation.rb', line 88 def jsonld_iiif graph.jsonld_iiif end |
#jsonld_oa ⇒ Object
Returns json-ld representation of anno with OpenAnnotation context as a url.
83 84 85 |
# File 'app/models/triannon/annotation.rb', line 83 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.
98 99 100 |
# File 'app/models/triannon/annotation.rb', line 98 def motivated_by graph.motivated_by if graph_exists? end |
#persisted? ⇒ Boolean
62 63 64 |
# File 'app/models/triannon/annotation.rb', line 62 def persisted? id.present? end |
#save ⇒ Object
Instance Methods —————————————————————-
45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/triannon/annotation.rb', line 45 def save _run_save_callbacks do # TODO: check if valid anno? @id = Triannon::LdpWriter.create_anno self 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 id id end end |