Class: Qa::Authorities::Subauthority

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

Overview

This is really just a sub-authority for Local

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Subauthority

Returns a new instance of Subauthority.



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

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.namesObject



33
34
35
36
37
38
39
40
# File 'lib/qa/authorities/local/subauthority.rb', line 33

def names
  @sub_auth_names ||=
    begin
      sub_auths = []
      Dir.foreach(sub_authorities_path) { |file| sub_auths << File.basename(file, File.extname(file)) }
      sub_auths
    end
end

.sub_authorities_pathObject



25
26
27
28
29
30
31
# File 'lib/qa/authorities/local/subauthority.rb', line 25

def sub_authorities_path
  config_path = AUTHORITIES_CONFIG[:local_path]
  if config_path.starts_with?(File::Separator)
    return config_path
  end
  File.join(Rails.root, config_path)
end

Instance Method Details

#full_record(id) ⇒ Object



20
21
22
# File 'lib/qa/authorities/local/subauthority.rb', line 20

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

#search(q) ⇒ Object



13
14
15
16
17
18
# File 'lib/qa/authorities/local/subauthority.rb', line 13

def search(q)
  r = q.blank? ? terms : terms.select { |term| /\b#{q.downcase}/.match(term[:term].downcase) }
  r.map do |res|
    { :id => res[:id], :label => res[:term] }.with_indifferent_access
  end
end

#termsObject



9
10
11
# File 'lib/qa/authorities/local/subauthority.rb', line 9

def terms
  @terms ||= load_sub_authority_terms
end