Cambridge Dict
Look up words for Cambridge via code or web server.
Installation
gem install cambridge_dict
Client Usage
# throws error
client = CambridgeDictionary::Client.lookup! "hello", "en"
# returns nil if not found
client = CambridgeDictionary::Client.lookup "hello", "en"
# can also create instance
client = CambridgeDictionary::Client.new
result = client.lookup("back", language: "en")
return if result.nil?
=>
{:word=>"back",
:pos=>["adverb", "noun", "verb", "adjective"],
:verbs=>
[{:id=>0, :type=>"Preposition", :text=>"back"},
{:id=>1, :type=>"Singular", :text=>"back"},
{:id=>2, :type=>"Plural", :text=>"backs"},
{:id=>3, :type=>"Plain form", :text=>"back"},
{:id=>4, :type=>"Third-person singular", :text=>"backs"},
{:id=>5, :type=>"Past tense", :text=>"backed"},
{:id=>6, :type=>"Past participle", :text=>"backed"},
{:id=>7, :type=>"Present participle", :text=>"backing"}],
:pronunciations=>
[{:pos=>"adverb", :lang=>"us", :url=>"https://dictionary.cambridge.org/us/media/english/us_pron/b/bac/back_/back.mp3", :pron=>"/bæk/"},
{:pos=>"adverb", :lang=>"uk", :url=>"https://dictionary.cambridge.org/us/media/english/uk_pron/u/uka/ukazt/ukazt__024.mp3", :pron=>"/bæk/"},
{:pos=>"noun", :lang=>"us", :url=>"https://dictionary.cambridge.org/us/media/english/us_pron/b/bac/back_/back.mp3", :pron=>"/bæk/"},
{:pos=>"noun", :lang=>"uk", :url=>"https://dictionary.cambridge.org/us/media/english/uk_pron/u/uka/ukazt/ukazt__024.mp3", :pron=>"/bæk/"},
{:pos=>"verb", :lang=>"us", :url=>"https://dictionary.cambridge.org/us/media/english/us_pron/b/bac/back_/back.mp3", :pron=>"/bæk/"},
...
:definitions=>
[{:id=>0,
:pos=>"adverb",
:headword=>"back",
:source=>"cald4-us",
:text=>"in, into, or toward a previous place or condition, or an earlier time: ",
:translation=>nil,
:example=>
[{:id=>0, :text=>"He looked back and saw they were following him.", :translation=>nil},
{:id=>1, :text=>"When you take the scissors, remember to put them back.", :translation=>nil},
{:id=>2, :text=>"Looking at her old photographs brought back (= made her remember) a lot of memories.", :translation=>nil},
{:id=>3, :text=>"He left a note saying \"Gone out. Back soon.\"", :translation=>nil},
{:id=>4, :text=>"She went to Brazil for two years, but now she's back.", :translation=>nil},
{:id=>5, :text=>"I was woken by a thunderstorm, and I couldn't get back to sleep (= could not sleep again).", :translation=>nil},
{:id=>6, :text=>"The last time we saw Lowell was back (= at an earlier time) in January.", :translation=>nil},
{:id=>7, :text=>"This tradition dates back to the 16th century.", :translation=>nil}]},
{:id=>1,
:pos=>"adverb",
:headword=>"back",
:source=>"cald4-us",
:text=>"in return: ",
:translation=>nil,
Webserver Setup
# add sinatra and sinatra-cors to gemfile
# config.ru
require 'cambridge_dict'
require 'cambridge_dict/server'
run CambridgeDict::Server
rackup config.ru
# curl localhost:9292/api/dictionary/:language/:word
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.