Class: Qa::Authorities::Local
Instance Attribute Summary
Attributes inherited from Base
#sub_authority
Instance Method Summary
collapse
#names, #sub_authorities_path
Methods inherited from Base
#full_record
Constructor Details
#initialize(*args) ⇒ Local
Returns a new instance of Local.
6
7
8
9
10
|
# File 'lib/qa/authorities/local.rb', line 6
def initialize *args
super
@sub_authority ||= args.first
raise "No sub-authority provided" if sub_authority.nil?
end
|
Instance Method Details
#all ⇒ Object
23
24
25
26
27
|
# File 'lib/qa/authorities/local.rb', line 23
def all
terms.map do |res|
{ :id => res[:id], :label => res[:term] }.with_indifferent_access
end
end
|
#find(id) ⇒ Object
29
30
31
|
# File 'lib/qa/authorities/local.rb', line 29
def find(id)
terms.find { |term| term[:id] == id } || {}
end
|
#search(q) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/qa/authorities/local.rb', line 16
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] }.with_indifferent_access
end
end
|
#sub_authorities ⇒ Object
12
13
14
|
# File 'lib/qa/authorities/local.rb', line 12
def sub_authorities
names
end
|