class Qa::Authorities::Local::FileBasedAuthority
Attributes
Public Class Methods
Source
# File lib/qa/authorities/local/file_based_authority.rb, line 4 def initialize(subauthority) super() @subauthority = subauthority end
Calls superclass method
Public Instance Methods
Source
# File lib/qa/authorities/local/file_based_authority.rb, line 16 def all terms.map do |res| { id: res[:id], label: res[:term], active: res.fetch(:active, true), uri: res.fetch(:uri, nil) } .compact.with_indifferent_access end end
Source
# File lib/qa/authorities/local/file_based_authority.rb, line 23 def find(id) terms.find { |term| term[:id] == id } || {} end
Source
# File lib/qa/authorities/local/file_based_authority.rb, line 9 def search(q) r = q.blank? ? [] : terms.select { |term| /\b#{q.downcase}/.match(term[:term].downcase) } r.map do |res| { id: res[:id], label: res[:term], uri: res.fetch(:uri, nil) }.compact.with_indifferent_access end end
Private Instance Methods
Source
# File lib/qa/authorities/local/file_based_authority.rb, line 39 def normalize_terms(terms) terms.map do |term| if term.is_a? String { id: term, term: term }.with_indifferent_access else term[:id] ||= term[:term] term end end end
Source
# File lib/qa/authorities/local/file_based_authority.rb, line 29 def terms subauthority_hash = YAML.load(File.read(subauthority_filename)) # rubocop:disable Security/YAMLLoad # TODO: Explore how to change this to safe_load. Many tests fail when making this change. terms = subauthority_hash.with_indifferent_access.fetch(:terms, []) normalize_terms(terms) end