class SearchYJ::Main
Public Instance Methods
detect(term, regexp, key = :title, **args)
click to toggle source
Detect a first record that meet the conditions of a regexp and a key. @param term [String] Search term @param regexp [Regexp] Want to match with value of a record @param key [Symbol] The key name for comparing values
@return [Hash]
A result record if matched the arguments Else nil
# File lib/searchyj/main.rb, line 14 def detect(term, regexp, key = :title, **args) key = key.to_sym unless key.is_a?(Symbol) searcher = Searcher.new(args) searcher.uri.search_term = term searcher.pager.size = 100 searcher.run do |record| if regexp.match(record[key]) return record end end nil end
list(term, size = 10, **args)
click to toggle source
Get records of the search result. @param term [String] Search term @param size [Integer] The size of the returner @param args [Hash]
@return [Array]
Includes the result records
# File lib/searchyj/main.rb, line 37 def list(term, size = 10, **args) searcher = Searcher.new(args) searcher.uri.search_term = term searcher.pager.size = size list = [] searcher.run do |record| list << record break if list.size >= size end list end
rank(term, rank, **args)
click to toggle source
Get a record in the search result at a particular rank order in the search ranking. @param term [String] Search term @param rank [Integer] The rank order in the search ranking
@return [Hash]
A result record if matched the arguments Else nil
# File lib/searchyj/main.rb, line 59 def rank(term, rank, **args) args[:from] = rank result = list(term, 1, args) (result.size > 0) ? result[0] : nil end