dictionary_lookup 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe5f411f5d33e70385be7ebb3fca21789501a3ac
4
- data.tar.gz: 8441dc3641878aa6665a755fcc779d0e7abfd157
3
+ metadata.gz: 629803c605ace4605aad3c5f4acc1c74ee34a91a
4
+ data.tar.gz: 7ae85ec0098a806397647320f568fb1b29783bdf
5
5
  SHA512:
6
- metadata.gz: 79c126b94b949b08c3b74054c954926dc1241372d8144a766c353acd3a7216befacff6c96e4d27fbf73c277281e6aaf0b0dca3a937346bd13612416896d52649
7
- data.tar.gz: 117ecfb6a80ff82b400163f20625038d497dc3eddbace8207ea2b00e980fd0e78feff4f6fe70d3a405b23f41a4dcec79563f717fa912f8f7eb03646403a0998d
6
+ metadata.gz: 2ac5bd92602355c61f1f9c02e4603ff8f7b285edebbda6c03108e81835ff83aeb2dd12d93ff3ba32b4da1ea71b51626fb6749b1d8af0a6d752782ed29321a6d0
7
+ data.tar.gz: 9eb97bb7109382ed2b7c9542da30607e21b8a63094c47d303845f57b621e55d25840fb8e8127e0aeb4b7e9ad8cbdaad70a3af310228944e6a392799caf54bf9b
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/dictionary_lookup.svg)](http://badge.fury.io/rb/dictionary_lookup)
4
4
  [![Build Status](https://travis-ci.org/nitishparkar/dictionary-lookup-rb.svg?branch=master)](https://travis-ci.org/nitishparkar/dictionary-lookup-rb)
5
5
 
6
- A ruby gem that wraps pearson dictionary API
6
+ A ruby gem that wraps [Pearson dictionary API](http://developer.pearson.com/apis/dictionaries)
7
7
 
8
8
  ## Getting started
9
9
 
@@ -37,3 +37,9 @@ results.first.part_of_speech # => "noun"
37
37
  results.first.denotation # => "used as a greeting when you see or meet someone"
38
38
  results.first.examples # => ["Hello, John! How are you?"]
39
39
  ```
40
+
41
+ You can specify different dictionary by passing `dictionary` in config hash. List of available dictionaries could be found [here](http://developer.pearson.com/apis/dictionaries#!//listDictionaryEntries)
42
+
43
+ ```ruby
44
+ results = DictionaryLookup::Base.define("hello", {dictionary: "wordwise"})
45
+ ```
@@ -7,8 +7,8 @@ module DictionaryLookup
7
7
  # @param (see Pearson.define)
8
8
  # @return (see Pearson.define)
9
9
  # @raise (see Pearson.define)
10
- def self.define(term)
11
- Pearson.define(term)
10
+ def self.define(term, config={})
11
+ Pearson.define(term, config)
12
12
  end
13
13
  end
14
14
  end
@@ -4,13 +4,29 @@ require "dictionary_lookup/definition"
4
4
 
5
5
  module DictionaryLookup
6
6
  class Pearson
7
+
8
+ VALID_DICTIONARIES = ["ldoce5", "lasde", "ldec", "wordwise", "laesd", "leasd", "laad3", "laes", "lase", "brep", "brpe"]
9
+
10
+ DEFAULT_DICTIONARY = VALID_DICTIONARIES.first
11
+
12
+ # Helper method. Returns either a valid dictionary specified through config
13
+ # or the default dictionary
14
+ def self.get_dictionary(config)
15
+ VALID_DICTIONARIES.include?(config[:dictionary]) ?
16
+ config[:dictionary] : DEFAULT_DICTIONARY
17
+ end
18
+
7
19
  # Fetches term definitions from Pearson dictionary API
8
20
  #
9
21
  # @param term [String] term to be defined
10
- # @return [Array] an array of DictionaryLookup::Definition objects
22
+ # @param config [Hash] configuration hash, for now supports :dictionary key.
23
+ # For list of valid values see {DictionaryLookup::Pearson::VALID_DICTIONARIES}
24
+ # @return [Array] an array of {DictionaryLookup::Definition} objects
11
25
  # @raise SocketError if not connected to the internet
12
- def self.define(term)
13
- url = "https://api.pearson.com:443/v2/dictionaries/ldoce5/entries?headword=#{term}"
26
+ def self.define(term, config)
27
+ dictionary = get_dictionary(config)
28
+
29
+ url = "https://api.pearson.com:443/v2/dictionaries/#{dictionary}/entries?headword=#{term}"
14
30
  uri = URI(URI.escape(url))
15
31
 
16
32
  response = Net::HTTP.get(uri)
@@ -23,7 +39,9 @@ module DictionaryLookup
23
39
 
24
40
  results.each do |result|
25
41
  part_of_speech = result["part_of_speech"]
26
- denotation = result["senses"].first["definition"].first
42
+ # In wordwise dictionary, value of definition is String. Hence the is_a? test
43
+ _definitions = result["senses"].first["definition"]
44
+ denotation = _definitions.is_a?(Array) ? _definitions.first : _definitions
27
45
  if result["senses"].first["examples"].nil?
28
46
  examples = []
29
47
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dictionary_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nitish Parkar