Skip to content

Instantly share code, notes, and snippets.

@andyl
Last active August 29, 2015 14:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Picky Example
#!/usr/bin/env ruby
require 'picky'
# create an index which is auto-saved into './index'
# note that :id is implied - every input object must supply an :id !
index = Picky::Index.new :people do
category :age
category :name
end
# define a data input class
# any object that responds to :id, :age, :name can be added to the index.
Person = Struct.new :id, :age, :name
# add some data objects to the index
# note that the IDs can be any unique string or integer
index.add Person.new(1, 34, 'Florian is the author of picky')
index.add Person.new(2, 77, 'Floris is related to Florian')
# create a search object
people = Picky::Search.new index
# do a search and save the results
search_results = people.search 'floris'
# show the results
puts search_results.ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment