Class: Qa::Authorities::Local::FileBasedAuthority

Inherits:
Base
  • Object
show all
Defined in:
lib/qa/authorities/local/file_based_authority.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subauthority) ⇒ FileBasedAuthority

Returns a new instance of FileBasedAuthority.



4
5
6
7
# File 'lib/qa/authorities/local/file_based_authority.rb', line 4

def initialize(subauthority)
  super()
  @subauthority = subauthority
end

Instance Attribute Details

#subauthorityObject (readonly)

Returns the value of attribute subauthority.



3
4
5
# File 'lib/qa/authorities/local/file_based_authority.rb', line 3

def subauthority
  @subauthority
end

Instance Method Details

#allObject



16
17
18
19
20
21
# 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

#find(id) ⇒ Object



23
24
25
# File 'lib/qa/authorities/local/file_based_authority.rb', line 23

def find(id)
  terms.find { |term| term[:id] == id } || {}
end

#search(q) ⇒ Object



9
10
11
12
13
14
# 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