Create a gist now

Instantly share code, notes, and snippets.

@myokoym /snippet.rb
Last active Aug 29, 2015

What would you like to do?
#!/usr/bin/env ruby
require "groonga"
db_path = ARGV[0] || File.expand_path("~/.feedcellar/db/feedcellar.db")
Groonga::Database.open(db_path) do |database|
feeds = Groonga["Feeds"]
selected_feeds = feeds.select do |feed|
feed.title =~ /Ruby/
end
expression = Groonga::Expression.new
variable = expression.define_variable(:domain => feeds)
expression.append_object(variable)
expression.parse("Ruby", :default_column => :title)
expression.compile
snippet = expression.snippet([["<mark>", "</mark>"]], :width => 30)
selected_feeds.each do |feed|
p snippet.execute(feed.title)
end
snippet.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment