Class: SearchYJ::Main
- Inherits:
-
Object
- Object
- SearchYJ::Main
- Defined in:
- lib/searchyj/main.rb
Instance Method Summary collapse
-
#detect(term, regexp, key = :title, **args) ⇒ Hash
Detect a first record that meet the conditions of a regexp and a key.
-
#list(term, size = 10, **args) ⇒ Array
Get records of the search result.
-
#rank(term, rank, **args) ⇒ Hash
Get a record in the search result at a particular rank order in the search ranking.
Instance Method Details
permalink #detect(term, regexp, key = :title, **args) ⇒ Hash
Detect a first record that meet the conditions of a regexp and a key.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 |
permalink #list(term, size = 10, **args) ⇒ Array
Get records of the search result.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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 |
permalink #rank(term, rank, **args) ⇒ Hash
Get a record in the search result at a particular rank order in the search ranking.
59 60 61 62 63 |
# 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 |