wordref 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a66711a2b2e83bc60ffd8c21bd2cb3c5d24c0baa
4
+ data.tar.gz: b9d336cf87765b902c1beeaecd59c49d49b4128f
5
+ SHA512:
6
+ metadata.gz: 35fa00278ac5ee5a98ed3303c18bbfdd49fe355597fc69720da4812d6da12dead5d066fb8e4aac526cd7880e367b6ad106992ad966b027e264807343ee55e4cd
7
+ data.tar.gz: 99c09185f264d45ccebde8d77566ac0a06b57ff7062e17851240ae537c5aebcb4ace926ca66fd53b4e7ef594354b7732a5dcddfbb285a365724cc538e8d7ae70
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wordref.gemspec
4
+ gemspec
@@ -0,0 +1,17 @@
1
+ # -*- encoding : utf-8 -*-
2
+ #
3
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
4
+ # Version 2, December 2004
5
+ #
6
+ # Copyright (C) 2004 Sam Hocevar
7
+ # 14 rue de Plaisance, 75014 Paris, France
8
+ # Everyone is permitted to copy and distribute verbatim or modified
9
+ # copies of this license document, and changing it is allowed as long
10
+ # as the name is changed.
11
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
12
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
14
+ #
15
+ #
16
+ # David Hagege <david.hagege@gmail.com>
17
+ #
@@ -0,0 +1,35 @@
1
+ # Wordref
2
+
3
+ Wordref is a tiny wrapper for the WordReference API.
4
+ You can translate words from one language to another (Note that Wordreference only supports FROM English and TO english translations)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'wordref'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install wordref
19
+
20
+ ## Usage
21
+
22
+ wr = Wordref::Wordref.new('your_api_key')
23
+
24
+ wr.translate(from: 'en', to: 'fr', 'cat') # => "chat"
25
+
26
+ If you don't give the "from" parameter it'll automatically be set to english.
27
+ That's all.
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,46 @@
1
+ # -*- encoding : utf-8 -*-
2
+ #
3
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
4
+ # Version 2, December 2004
5
+ #
6
+ # Copyright (C) 2004 Sam Hocevar
7
+ # 14 rue de Plaisance, 75014 Paris, France
8
+ # Everyone is permitted to copy and distribute verbatim or modified
9
+ # copies of this license document, and changing it is allowed as long
10
+ # as the name is changed.
11
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
12
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
14
+ #
15
+ #
16
+ # David Hagege <david.hagege@gmail.com>
17
+ #
18
+
19
+ require "wordref/version"
20
+ require 'open-uri'
21
+ require 'multi_json'
22
+ require 'attempt'
23
+
24
+ module Wordref
25
+
26
+ class Wordref
27
+ def initialize(api_key)
28
+ @api_key = api_key
29
+ end
30
+
31
+ def translate(params = {})
32
+ dic = "#{params[:from] || 'en'}#{params[:to]}"
33
+ word = params[:word]
34
+
35
+ response = attempt(3, 3) {
36
+ open("http://api.wordreference.com/#{@api_key}/json/#{dic}/#{URI::encode(word)}").read
37
+ }
38
+ response.gsub!(/\t/, ' ')
39
+ json = MultiJson.load(response)['term0']
40
+ return "" if json.nil?
41
+ data = json['PrincipalTranslations'] || json['Entries']
42
+ data.first[1]['FirstTranslation']['term']
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,3 @@
1
+ module Wordref
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding : utf-8 -*-
2
+ #
3
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
4
+ # Version 2, December 2004
5
+ #
6
+ # Copyright (C) 2004 Sam Hocevar
7
+ # 14 rue de Plaisance, 75014 Paris, France
8
+ # Everyone is permitted to copy and distribute verbatim or modified
9
+ # copies of this license document, and changing it is allowed as long
10
+ # as the name is changed.
11
+ # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
12
+ # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13
+ # 0. You just DO WHAT THE FUCK YOU WANT TO.
14
+ #
15
+ #
16
+ # David Hagege <david.hagege@gmail.com>
17
+ #
18
+
19
+ require 'wordref'
20
+
21
+ describe Wordref do
22
+ it "can translate the word car in french" do
23
+ tr = Wordref::Wordref.new('your_api_key')
24
+ tr.translate(from: 'en', to: 'fr', word: 'car').should eql("voiture")
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wordref/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "wordref"
8
+ gem.version = Wordref::VERSION
9
+ gem.authors = ["pcboy"]
10
+ gem.email = ["david.hagege@gmail.com"]
11
+ gem.description = %q{Tiny gem to translate words with the WordReference API}
12
+ gem.summary = ""
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency "multi_json"
20
+ gem.add_dependency "attempt"
21
+ gem.add_development_dependency "rspec"
22
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wordref
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - pcboy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: attempt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Tiny gem to translate words with the WordReference API
56
+ email:
57
+ - david.hagege@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/wordref.rb
68
+ - lib/wordref/version.rb
69
+ - spec/wordref_spec.rb
70
+ - wordref.gemspec
71
+ homepage: ''
72
+ licenses: []
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.0.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: ''
94
+ test_files:
95
+ - spec/wordref_spec.rb