Class: Hyrax::QaSelectService
- Inherits:
-
Object
- Object
- Hyrax::QaSelectService
- Defined in:
- app/services/hyrax/qa_select_service.rb
Overview
This is an abstract class to provide select options from a questioning authority backed authority
Direct Known Subclasses
LicenseService, RightsStatementService, TolerantSelectService
Instance Attribute Summary collapse
-
#authority ⇒ Object
readonly
Returns the value of attribute authority.
Instance Method Summary collapse
-
#active?(id) ⇒ Boolean
Whether the key is active.
- #active_elements ⇒ Enumerable<Hash>
-
#include_current_value(value, _index, render_options, html_options) ⇒ Object
A helper for adding the current value to a form dropdown when.
-
#initialize(authority_name) ⇒ QaSelectService
constructor
A new instance of QaSelectService.
-
#label(id) { ... } ⇒ String
The label for the authority.
- #select_active_options ⇒ Array<String, #to_s>
- #select_all_options ⇒ Array<String, #to_s>
Constructor Details
#initialize(authority_name) ⇒ QaSelectService
Returns a new instance of QaSelectService.
7 8 9 |
# File 'app/services/hyrax/qa_select_service.rb', line 7 def initialize() @authority = Qa::Authorities::Local.() end |
Instance Attribute Details
#authority ⇒ Object (readonly)
Returns the value of attribute authority.
5 6 7 |
# File 'app/services/hyrax/qa_select_service.rb', line 5 def @authority end |
Instance Method Details
#active?(id) ⇒ Boolean
Returns whether the key is active.
28 29 30 |
# File 'app/services/hyrax/qa_select_service.rb', line 28 def active?(id) .find(id).fetch('active') end |
#active_elements ⇒ Enumerable<Hash>
49 50 51 |
# File 'app/services/hyrax/qa_select_service.rb', line 49 def active_elements .all.select { |e| e.fetch('active') } end |
#include_current_value(value, _index, render_options, html_options) ⇒ Object
find a better home for this! This was initially inlined to the service from a helper module in github.com/samvera/curation_concerns/pull/986. It seems odd that this service knows about HTML rendering details. Maybe a factory is an appropriate next step?
this was extracted from LicenseService for more general use.
A helper for adding the current value to a form dropdown when
62 63 64 65 66 67 68 |
# File 'app/services/hyrax/qa_select_service.rb', line 62 def include_current_value(value, _index, , ) unless value.blank? || active?(value) [:class] << ' force-select' += [[label(value) { value }, value]] end [, ] end |
#label(id) { ... } ⇒ String
Returns the label for the authority.
41 42 43 |
# File 'app/services/hyrax/qa_select_service.rb', line 41 def label(id, &block) .find(id).fetch('term', &block) end |
#select_active_options ⇒ Array<String, #to_s>
20 21 22 |
# File 'app/services/hyrax/qa_select_service.rb', line 20 def active_elements.map { |e| [e[:label], e[:id]] } end |
#select_all_options ⇒ Array<String, #to_s>
13 14 15 16 17 |
# File 'app/services/hyrax/qa_select_service.rb', line 13 def .all.map do |element| [element[:label], element[:id]] end end |