Skip to content

Instantly share code, notes, and snippets.

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