Class: Qa::Authorities::Local::FileBasedAuthority
- Defined in:
- lib/qa/authorities/local/file_based_authority.rb
Instance Attribute Summary collapse
-
#subauthority ⇒ Object
readonly
Returns the value of attribute subauthority.
Instance Method Summary collapse
- #all ⇒ Object
- #find(id) ⇒ Object
-
#initialize(subauthority) ⇒ FileBasedAuthority
constructor
A new instance of FileBasedAuthority.
- #search(q) ⇒ Object
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() super() @subauthority = end |
Instance Attribute Details
#subauthority ⇒ Object (readonly)
Returns the value of attribute subauthority.
3 4 5 |
# File 'lib/qa/authorities/local/file_based_authority.rb', line 3 def @subauthority end |
Instance Method Details
#all ⇒ Object
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 |