Sha256: 4280c7a868b8ff67b6ca88270f4332bf521635dbb58ca9d3c61e4cc2ba1f031c
Contents?: true
Size: 776 Bytes
Versions: 21
Compression:
Stored size: 776 Bytes
Contents
require 'sinatra/base' module Voom module Presenters module Demo class Search < Sinatra::Base get('/_search_') do content_type :json JSON.dump(search(params[:search])) end def search(term) require 'yaml' return [] unless term @terms ||= YAML::load_file(File.join(__dir__, './search-terms.yml')) @terms.keys.reduce([]) do |matches, topic| @terms[topic].reduce(matches) do |matches, item| matches << [item, matches.length] if item.downcase.include?(term.downcase) matches end end end # start the server if ruby file executed directly run! if app_file == $0 end end end end
Version data entries
21 entries across 21 versions & 1 rubygems