Ruby/DICT - client-side DICT protocol library
require 'dict' dict = DICT.new('dict.org', DICT::DEFAULT_PORT) dict.client('a Ruby/DICT client') definitions = dict.define(DICT::ALL_DATABASES, 'ruby') if definitions definitions.each do |d| printf("From %s [%s]:\n\n", d.description, d.database) d.definition.each { |line| print line } end end dict.disconnect
Ruby/DICT is a client-side library implementation of the DICT protocol, as described in RFC 2229.
DICT.new(hosts, port = DICT::DEFAULT_PORT, debug = false, verbose = false)
DICT#disconnect
DICT#define(database, word)
Obtain definitions for word from database. A list of valid databases can be obtained using DICT#show(DICT::DATABASES).
To show just the first definition found, use DICT::FIRST_DATABASE as the database name. To show definitions from all databases, use DICT::ALL_DATABASES.
On success, this returns an array of Struct:Definition objects. nil is returned on failure.
DICT#match(database, strategy, word)
Obtain matches for word from database using strategy.
On success, a hash of arrays is returned. The keys of the hash are the database names and the values are arrays of word matches that were found in that database. nil is returned on failure.
DICT#show_server
This method retrieves information on the server itself.
A String is returned on success, while nil is returned on failure.
DICT#show_db
This method retrieves information on the databases offered by the server.
A Hash indexed on database name and containing database descriptions is returned on success, while nil is returned on failure.
DICT#show_info(database)
This method retrieves information on a particular database offered by the server.
A String is returned on success, while nil is returned on failure.
DICT#show_strat
This method retrieves information on the strategies offered by the server.
A Hash indexed on strategy name and containing strategy descriptions is returned on success, while nil is returned on failure.
DICT#status
DICT#help
DICT#client
DICT#auth(user, secret)
Ruby/DICT uses a lot of constants, mostly for the status codes returned by DICT servers. See the source for details.
Some of the more interesting other constants:
Exception classes are subclasses of the container class DICTError, which is, itself, a subclass of RuntimeError
ConnectError.new(message, code = 2)
ProtocolError.new(message, code = 3)
Written by Ian Macdonald <ian@caliban.org>
Copyright (C) 2002-2007 Ian Macdonald This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Send all bug reports, enhancement requests and patches to the author.
$Id: dict.rb,v 1.29 2007/05/20 00:01:36 ianmacd Exp $