metanym 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/.gitignore +4 -0
  2. data/LICENSE +20 -0
  3. data/README.md +18 -0
  4. data/lib/metanym.rb +42 -0
  5. data/metanym.gemspec +19 -0
  6. metadata +82 -0
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Lee Jarvis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ Metanym
2
+ =======
3
+
4
+ Search thesaurus.com for Synonyms and Antonyms
5
+
6
+ Installation
7
+ ============
8
+
9
+ gem install metanym
10
+
11
+ Usage
12
+ =====
13
+
14
+ require 'metanym'
15
+
16
+ query = Metanym.new 'hello'
17
+ p query.synonyms #=> ["bonjour", "buenas noches", "buenos dias", ...]
18
+ p query.antonyms #=> ["adios", "au revoir", "goodbye"]
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'excon'
4
+ require 'nokogiri'
5
+
6
+ class Metanym
7
+ VERSION = "0.1.0"
8
+ URL = "http://thesaurus.com/browse/"
9
+
10
+ def initialize(query)
11
+ @url = URI.encode(URL + query)
12
+ end
13
+
14
+ def synonyms
15
+ @synonyms ||= items_at 'Synonyms'
16
+ end
17
+
18
+ def antonyms
19
+ @antonyms ||= items_at 'Antonyms'
20
+ end
21
+
22
+ def definition
23
+ @definition ||= doc.at_xpath('//td[.="Definition:"]/following::td').text
24
+ rescue NoMethodError
25
+ nil
26
+ end
27
+
28
+ def items_at(head)
29
+ doc.at_xpath("//td[.='#{head}:']/following-sibling::td").text.strip.split(/[\n,]\s*/)
30
+ rescue NoMethodError
31
+ []
32
+ end
33
+
34
+ def doc
35
+ @doc ||= Nokogiri.HTML source
36
+ end
37
+
38
+ def source
39
+ Excon.get(@url, :expects => 200).body
40
+ end
41
+
42
+ end
@@ -0,0 +1,19 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "metanym"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "metanym"
6
+ s.version = Metanym::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Lee Jarvis"]
9
+ s.email = ["lee@jarvis.co"]
10
+ s.homepage = "http://github.com/injekt/metanym"
11
+ s.summary = %q{Search thesaurus.com for synonyms/antonyms}
12
+ s.description = %q{Search thesaurus.com for synonyms/antonyms}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.require_paths = ["lib"]
16
+
17
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.4"])
18
+ s.add_runtime_dependency(%q<excon>, [">= 0.5.6"])
19
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metanym
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Lee Jarvis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-03-25 00:00:00 +00:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: nokogiri
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.4.4
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: excon
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.5.6
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: Search thesaurus.com for synonyms/antonyms
39
+ email:
40
+ - lee@jarvis.co
41
+ executables: []
42
+
43
+ extensions: []
44
+
45
+ extra_rdoc_files: []
46
+
47
+ files:
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.md
51
+ - lib/metanym.rb
52
+ - metanym.gemspec
53
+ has_rdoc: true
54
+ homepage: http://github.com/injekt/metanym
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.6.2
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Search thesaurus.com for synonyms/antonyms
81
+ test_files: []
82
+