Sha256: b012169685d513bda19d141125ecabd0ec18afc78b603c5596a5816b6a3f971f
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
#!/usr/bin/env ruby require 'optparse' options = {} option_parser = OptionParser.new do |opts| opts.banner = "Example: dict hello" opts.on("-p", "--[no-]pronounce", "Pronounce the word") do |v| options[:pronounce] = v end opts.on("-c", "--[no-]cache", "Use cache from ~/.bing_dictionary.db (Default on)") do |v| options[:cache] = v end opts.on("-j", "--jump", "Jump to web page") do |v| options[:jump] = v end opts.on("-v", "--version", "Show the version") do |v| options[:version] = v end end if ARGV.empty? option_parser.parse('--help') else option_parser.parse! word = ARGV.join(' ') if options[:version] require "bing_dictionary" puts BingDictionary::VERSION elsif options[:jump] `open http://cn.bing.com/dict/?q=#{CGI::escape(word)}` else require 'dbm' DBM.open(File.join(Dir.home, '.bing_dictionary')) do |cache| if cache.key?(word) && options[:cache] != false puts cache[word] else require "bing_dictionary" backup = $stdout $stdout = StringIO.new BingDictionary::Base.translate(word, options) out = $stdout.string $stdout = backup if out && out.length > 0 cache[word] = out puts out end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
bing_dictionary-0.1.7 | bin/dict |
bing_dictionary-0.1.6 | bin/dict |
bing_dictionary-0.1.5 | bin/dict |