Class: BlacklightIiifSearch::IiifSearchAnnotation

Inherits:
Object
  • Object
show all
Includes:
AnnotationBehavior, IIIF::Presentation
Defined in:
app/models/blacklight_iiif_search/iiif_search_annotation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AnnotationBehavior

#annotation_id, #canvas_uri_for_annotation, #coordinates

Constructor Details

#initialize(document, query, hl_index, snippet, controller, parent_document) ⇒ IiifSearchAnnotation

rubocop:disable Metrics/ParameterLists

Parameters:

  • document (SolrDocument)
  • query (String)
  • hl_index (Integer)
  • snippet (String)
  • controller (CatalogController)
  • parent_document (SolrDocument)


20
21
22
23
24
25
26
27
# File 'app/models/blacklight_iiif_search/iiif_search_annotation.rb', line 20

def initialize(document, query, hl_index, snippet, controller, parent_document)
  @document = document
  @query = query
  @hl_index = hl_index
  @snippet = snippet
  @controller = controller
  @parent_document = parent_document
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



9
10
11
# File 'app/models/blacklight_iiif_search/iiif_search_annotation.rb', line 9

def controller
  @controller
end

#documentObject (readonly)

Returns the value of attribute document.



9
10
11
# File 'app/models/blacklight_iiif_search/iiif_search_annotation.rb', line 9

def document
  @document
end

#hl_indexObject (readonly)

Returns the value of attribute hl_index.



9
10
11
# File 'app/models/blacklight_iiif_search/iiif_search_annotation.rb', line 9

def hl_index
  @hl_index
end

#parent_documentObject (readonly)

Returns the value of attribute parent_document.



9
10
11
# File 'app/models/blacklight_iiif_search/iiif_search_annotation.rb', line 9

def parent_document
  @parent_document
end

#queryObject (readonly)

Returns the value of attribute query.



9
10
11
# File 'app/models/blacklight_iiif_search/iiif_search_annotation.rb', line 9

def query
  @query
end

#snippetObject (readonly)

Returns the value of attribute snippet.



9
10
11
# File 'app/models/blacklight_iiif_search/iiif_search_annotation.rb', line 9

def snippet
  @snippet
end

Instance Method Details

#as_hashIIIF::Presentation::Annotation

Returns:

  • (IIIF::Presentation::Annotation)


32
33
34
35
36
37
# File 'app/models/blacklight_iiif_search/iiif_search_annotation.rb', line 32

def as_hash
  annotation = IIIF::Presentation::Annotation.new('@id' => annotation_id)
  annotation.resource = text_resource_for_annotation if snippet
  annotation['on'] = canvas_uri_for_annotation
  annotation
end

#text_resource_for_annotationIIIF::Presentation::Resource

Returns:

  • (IIIF::Presentation::Resource)


41
42
43
44
45
# File 'app/models/blacklight_iiif_search/iiif_search_annotation.rb', line 41

def text_resource_for_annotation
  clean_snippet = ActionView::Base.full_sanitizer.sanitize(snippet)
  IIIF::Presentation::Resource.new('@type' => 'cnt:ContentAsText',
                                   'chars' => clean_snippet)
end