Class: Appydave::Tools::BrainQuery
- Inherits:
-
Object
- Object
- Appydave::Tools::BrainQuery
- Defined in:
- lib/appydave/tools/brain_context/brain_finder.rb
Overview
Queries brains-index.json to find brain files
Instance Method Summary collapse
- #find ⇒ Object
- #find_meta ⇒ Object
-
#initialize(options) ⇒ BrainQuery
constructor
A new instance of BrainQuery.
Constructor Details
#initialize(options) ⇒ BrainQuery
Returns a new instance of BrainQuery.
9 10 11 12 13 |
# File 'lib/appydave/tools/brain_context/brain_finder.rb', line 9 def initialize() @options = @index = nil @alias_map = nil end |
Instance Method Details
#find ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/appydave/tools/brain_context/brain_finder.rb', line 15 def find return [] unless @options.brain_query? load_index! paths = [] # Active brains: return all high-activity brains paths.concat(find_active) if @options.active # Handle brain name/tag/alias queries (unified) @options.brain_names.each do |name| paths.concat(find_by_name(name)) end # Handle category queries @options.categories.each do |category| paths.concat(find_by_category(category)) end paths.uniq.sort end |
#find_meta ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/appydave/tools/brain_context/brain_finder.rb', line 37 def return [] unless @options.brain_query? load_index! entries = [] entries.concat() if @options.active @options.brain_names.each { |name| entries.concat((name)) } @options.categories.each { |cat| entries.concat((cat)) } entries.uniq { |e| e['name'] }.sort_by { |e| e['name'] } end |