Class: WorkPresenter
- Inherits:
-
Object
- Object
- WorkPresenter
- Defined in:
- app/presenters/work_presenter.rb
Instance Attribute Summary collapse
-
#work ⇒ Object
readonly
Returns the value of attribute work.
Instance Method Summary collapse
- #description ⇒ Object
-
#format_link(id, id_type) ⇒ Object
Turn an identifier into a link.
-
#format_related_object_links(related_object) ⇒ Object
relation_type, identifier, link.
-
#initialize(work:) ⇒ WorkPresenter
constructor
A new instance of WorkPresenter.
- #related_objects_link_list ⇒ Object
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
#work ⇒ Object (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
#description ⇒ Object
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 |
#format_link(id, id_type) ⇒ Object
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 |
#format_related_object_links(related_object) ⇒ Object
relation_type, identifier, link
23 24 25 26 27 28 29 |
# File 'app/presenters/work_presenter.rb', line 23 def () rol = RelatedObjectLink.new rol.identifier = . rol.relation_type = .relation_type rol.link = format_link(., .) rol end |
#related_objects_link_list ⇒ Object
17 18 19 20 |
# File 'app/presenters/work_presenter.rb', line 17 def ro = resource. ro.map { |a| (a) } end |