Class: Qa::Authorities::Subauthority
- Inherits:
-
Object
- Object
- Qa::Authorities::Subauthority
- Defined in:
- lib/qa/authorities/local/subauthority.rb
Overview
This is really just a sub-authority for Local
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #full_record(id) ⇒ Object
-
#initialize(name) ⇒ Subauthority
constructor
A new instance of Subauthority.
- #search(q) ⇒ Object
- #terms ⇒ Object
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
#name ⇒ Object (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
.names ⇒ Object
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() { |file| sub_auths << File.basename(file, File.extname(file)) } sub_auths end end |
.sub_authorities_path ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/qa/authorities/local/subauthority.rb', line 25 def 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 |
#terms ⇒ Object
9 10 11 |
# File 'lib/qa/authorities/local/subauthority.rb', line 9 def terms @terms ||= end |