Class: Reditor::LibrarySearchQuery
- Inherits:
-
Object
- Object
- Reditor::LibrarySearchQuery
- Includes:
- BundlerSupport
- Defined in:
- lib/reditor/library_search_query.rb
Instance Attribute Summary collapse
-
#half_pattern ⇒ Object
readonly
Returns the value of attribute half_pattern.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#partial_pattern ⇒ Object
readonly
Returns the value of attribute partial_pattern.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Class Method Summary collapse
Instance Method Summary collapse
- #candidates ⇒ Object
-
#initialize(query, options = {}) ⇒ LibrarySearchQuery
constructor
A new instance of LibrarySearchQuery.
- #search(limit = options[:limit]) ⇒ Object
Methods included from BundlerSupport
Constructor Details
#initialize(query, options = {}) ⇒ LibrarySearchQuery
Returns a new instance of LibrarySearchQuery.
15 16 17 18 19 20 21 22 |
# File 'lib/reditor/library_search_query.rb', line 15 def initialize(query, = {}) @query = query.to_s @options = {limit: 20, global: false}.merge() quoted = Regexp.quote(query) @half_pattern = /^#{quoted}|#{quoted}$/i @partial_pattern = /#{quoted}/i end |
Instance Attribute Details
#half_pattern ⇒ Object (readonly)
Returns the value of attribute half_pattern.
13 14 15 |
# File 'lib/reditor/library_search_query.rb', line 13 def half_pattern @half_pattern end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/reditor/library_search_query.rb', line 12 def @options end |
#partial_pattern ⇒ Object (readonly)
Returns the value of attribute partial_pattern.
13 14 15 |
# File 'lib/reditor/library_search_query.rb', line 13 def partial_pattern @partial_pattern end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
12 13 14 |
# File 'lib/reditor/library_search_query.rb', line 12 def query @query end |
Class Method Details
.search(query, options = {}) ⇒ Object
8 9 10 |
# File 'lib/reditor/library_search_query.rb', line 8 def self.search(query, = {}) new(query, ).search end |
Instance Method Details
#candidates ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/reditor/library_search_query.rb', line 30 def candidates @candidates ||= ( candidates_from_loadpath + candidates_from_gem + candidates_from_bundler ).uniq end |
#search(limit = options[:limit]) ⇒ Object
24 25 26 27 28 |
# File 'lib/reditor/library_search_query.rb', line 24 def search(limit = [:limit]) candidates.sort_by {|name| [*match_scores(name), *distance_scores(name), name] }.take(limit) end |