Class: WorkPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/work_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(work:) ⇒ WorkPresenter

Returns a new instance of WorkPresenter.



7
8
9
# File 'app/presenters/work_presenter.rb', line 7

def initialize(work:)
  @work = work
end

Instance Attribute Details

#workObject (readonly)

Returns the value of attribute work.



3
4
5
# File 'app/presenters/work_presenter.rb', line 3

def work
  @work
end

Instance Method Details

#descriptionObject



11
12
13
14
15
# File 'app/presenters/work_presenter.rb', line 11

def description
  value = resource.description
  return if value.nil?
  Rinku.auto_link(value, :all, 'target="_blank"')
end

Turn an identifier into a link. This will vary for different kinds of related objects. A DOI URL is not the same as an arXiv URL, for example. For now, only format links for DOI and arXiv identifiers



34
35
36
37
38
39
# File 'app/presenters/work_presenter.rb', line 34

def format_link(id, id_type)
  return id if id.starts_with?("http")
  return "https://doi.org/#{id}" if id_type == "DOI"
  return "https://arxiv.org/abs/#{id}" if id_type == "arXiv"
  ""
end

relation_type, identifier, link



23
24
25
26
27
28
29
# File 'app/presenters/work_presenter.rb', line 23

def format_related_object_links(related_object)
  rol = RelatedObjectLink.new
  rol.identifier = related_object.related_identifier
  rol.relation_type = related_object.relation_type
  rol.link = format_link(related_object.related_identifier, related_object.related_identifier_type)
  rol
end


17
18
19
20
# File 'app/presenters/work_presenter.rb', line 17

def related_objects_link_list
  ro = resource.related_objects
  ro.map { |a| format_related_object_links(a) }
end