Sha256: d4b88d3dab0a6add212982b26c43e0aece9fe0f2aa6d2d24822775712b4ac9fe

Contents?: true

Size: 742 Bytes

Versions: 10

Compression:

Stored size: 742 Bytes

Contents

module Hyrax
  # This is an abstract class to provide select options from a
  # questioning authority backed authority
  class QaSelectService
    attr_reader :authority

    def initialize(authority_name)
      @authority = Qa::Authorities::Local.subauthority_for(authority_name)
    end

    def select_all_options
      authority.all.map do |element|
        [element[:label], element[:id]]
      end
    end

    def select_active_options
      active_elements.map { |e| [e[:label], e[:id]] }
    end

    def active?(id)
      authority.find(id).fetch('active')
    end

    def label(id)
      authority.find(id).fetch('term')
    end

    def active_elements
      authority.all.select { |e| active?(e.fetch('id')) }
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
hyrax-1.1.1 app/services/hyrax/qa_select_service.rb
hyrax-1.1.0 app/services/hyrax/qa_select_service.rb
hyrax-1.0.5 app/services/hyrax/qa_select_service.rb
hyrax-1.0.4 app/services/hyrax/qa_select_service.rb
hyrax-1.0.3 app/services/hyrax/qa_select_service.rb
hyrax-1.0.2 app/services/hyrax/qa_select_service.rb
hyrax-1.0.1 app/services/hyrax/qa_select_service.rb
hyrax-1.0.0.rc2 app/services/hyrax/qa_select_service.rb
hyrax-1.0.0.rc1 app/services/hyrax/qa_select_service.rb
test_hyrax-0.0.1.alpha app/services/hyrax/qa_select_service.rb