dictionary_lookup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9dbf32d1b9cd363fe86ce55d059a45476762a84e
4
+ data.tar.gz: 088862d3ae6fadf85a007d1e4fa08954b37911e1
5
+ SHA512:
6
+ metadata.gz: ededd2aa79156b4f0969c5c518e20d3f65a4769e6a1eec3ca462584a615bd8339d42571f8811e67cebaf6728bcc2ce14ff29fdfcf7e2fb8ae9e96c8251f72c5e
7
+ data.tar.gz: bd163f7f2ea4b2f5dee2608280dbe8a79e2918fc43c7f4b211a868730ae02595ab4db41d804ce3bd60a5f3390fc9a266c3ae5e908ae16d9f49d634071f8e806f
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nitish Parkar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Dictionary Lookup
2
+
3
+ A ruby gem that wraps pearson dictionary API
4
+
5
+ ## Getting started
6
+
7
+ You can add it to your Gemfile with:
8
+
9
+ ```ruby
10
+ gem 'dictionary_lookup'
11
+ ```
12
+ or
13
+
14
+ You can install it directly
15
+
16
+ gem install dictionary_lookup
17
+
18
+ and then require it
19
+
20
+ require 'dictionary_lookup'
21
+
22
+ ## Usage
23
+
24
+ You can lookup a word definition by:
25
+
26
+ ```ruby
27
+ results = DictionaryLookup::Base.define("hello")
28
+ ```
29
+
30
+ results will contain an array of DictionaryLookup::Definition objects.
31
+ ```ruby
32
+ results.count # => 1
33
+ results.first.part_of_speech # => "noun"
34
+ results.first.denotation # => "used as a greeting when you see or meet someone"
35
+ results.first.examples # => ["Hello, John! How are you?"]
36
+ ```
@@ -0,0 +1,11 @@
1
+ module DictionaryLookup
2
+ class Definition
3
+ attr_accessor :part_of_speech, :denotation, :examples
4
+
5
+ def initialize(part_of_speech, denotation, examples)
6
+ @part_of_speech = part_of_speech
7
+ @denotation = denotation
8
+ @examples = examples
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ require "net/http"
2
+ require "json"
3
+ require "dictionary_lookup/definition"
4
+
5
+ module DictionaryLookup
6
+ class Pearson
7
+ # Fetches term definitions from Pearson dictionary API
8
+ #
9
+ # @param term [String] term to be defined
10
+ # @return [Array] an array of DictionaryLookup::Definition objects
11
+ # @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}"
14
+ uri = URI(URI.escape(url))
15
+
16
+ response = Net::HTTP.get(uri)
17
+ data = JSON.parse(response)
18
+
19
+ # Select definitions that match exactly with the term
20
+ results = data["results"].select{ |d| d["headword"].downcase == term.downcase }
21
+
22
+ definitions = []
23
+
24
+ results.each do |result|
25
+ part_of_speech = result["part_of_speech"]
26
+ denotation = result["senses"].first["definition"].first
27
+ if result["senses"].first["examples"].nil?
28
+ examples = []
29
+ else
30
+ examples = result["senses"].first["examples"].map{|e| e["text"]}
31
+ end
32
+ definitions << DictionaryLookup::Definition.new(part_of_speech, denotation, examples)
33
+ end
34
+
35
+ definitions
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ require "dictionary_lookup/pearson"
2
+
3
+ module DictionaryLookup
4
+ class Base
5
+ # Handles a lookup request
6
+ #
7
+ # @param (see Pearson.define)
8
+ # @return (see Pearson.define)
9
+ # @raise (see Pearson.define)
10
+ def self.define(term)
11
+ Pearson.define(term)
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dictionary_lookup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nitish Parkar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: developer.nitish@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - README.md
21
+ - lib/dictionary_lookup.rb
22
+ - lib/dictionary_lookup/definition.rb
23
+ - lib/dictionary_lookup/pearson.rb
24
+ homepage: https://github.com/nitishparkar/dictionary-lookup-rb
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.2.2
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: A ruby gem that wraps pearson dictionary API
48
+ test_files: []
49
+ has_rdoc: