Class: LD4L::OpenAnnotationRDF::CommentAnnotation
- Inherits:
-
Annotation
- Object
- ActiveTriples::Resource
- Annotation
- LD4L::OpenAnnotationRDF::CommentAnnotation
- Defined in:
- lib/ld4l/open_annotation_rdf/comment_annotation.rb
Instance Method Summary collapse
-
#getComment ⇒ Object
Get the value of the comment stored in a comment annotation.
-
#initialize(*args) ⇒ CommentAnnotation
constructor
Special processing for new and resumed CommentAnnotations.
-
#setComment(comment) ⇒ Object
Create a comment annotation body and set the hasBody property to it.
Methods inherited from Annotation
find_by_target, #getBody, #persist!, resume, #setAnnotatedAtNow
Constructor Details
#initialize(*args) ⇒ CommentAnnotation
Special processing for new and resumed CommentAnnotations
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ld4l/open_annotation_rdf/comment_annotation.rb', line 48 def initialize(*args) super(*args) # set motivatedBy m = get_values(:motivatedBy) m = m.to_a if Object::ActiveTriples.const_defined?("Relation") && m.kind_of?(ActiveTriples::Relation) set_value(:motivatedBy, RDF::Vocab::OA.commenting) unless m.kind_of?(Array) && m.size > 0 # resume CommentBody if it exists comment_uri = get_values(:hasBody).first if( comment_uri ) comment_uri = comment_uri.rdf_subject if comment_uri.kind_of?(ActiveTriples::Resource) @body = LD4L::OpenAnnotationRDF::CommentBody.new(comment_uri) end end |
Instance Method Details
#getComment ⇒ Object
Get the value of the comment stored in a comment annotation.
40 41 42 43 |
# File 'lib/ld4l/open_annotation_rdf/comment_annotation.rb', line 40 def getComment comments = @body.content comments && comments.size > 0 ? comments.first : "" end |
#setComment(comment) ⇒ Object
Create a comment annotation body and set the hasBody property to it.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ld4l/open_annotation_rdf/comment_annotation.rb', line 17 def setComment(comment) @body ||= hasBody.first if hasBody.size > 0 if self.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8 @body ||= LD4L::OpenAnnotationRDF::CommentBody.new( ActiveTriples::LocalName::Minter.generate_local_name( LD4L::OpenAnnotationRDF::CommentBody, 10, @localname_prefix, LD4L::OpenAnnotationRDF.configuration.localname_minter),self) else # < ActiveTriples 0.8 @body ||= LD4L::OpenAnnotationRDF::CommentBody.new( ActiveTriples::LocalName::Minter.generate_local_name( LD4L::OpenAnnotationRDF::CommentBody, 10, @localname_prefix, LD4L::OpenAnnotationRDF.configuration.localname_minter)) end @body.content = comment @body.format = "text/plain" set_value(:hasBody, @body) @body end |