wordref 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -3
- data/README.md +1 -1
- data/lib/wordref.rb +52 -3
- data/lib/wordref/version.rb +1 -1
- data/spec/lib/wordref_spec.rb +6 -0
- data/wordref.gemspec +1 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 643ffe4ebd8d70865ba00fc99609517475be690b
|
4
|
+
data.tar.gz: 094998062cb8402aea15c78b132a34ab295bc184
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3496c76bfb1456ae7d4af8c9794a8af008ba24fe65a47d2320ad61eb93ff0d724474ceef8d8a868640f2349041aa860aa6af26627e9ba495eaa979a451e21f1a
|
7
|
+
data.tar.gz: bf471cf38773268ed5c0ad79ade7f9a6f18d8ffbec023e49413d39ddfa8e854bc0cb438c7fd241fc90d4870938fc55eacb93d15407c8b0fad2c6d05192ed6a8a
|
data/.travis.yml
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
rvm:
|
4
|
-
|
5
|
-
|
6
|
-
script: rake
|
4
|
+
- 1.9.2
|
5
|
+
- jruby-19mode
|
6
|
+
script: rake
|
7
|
+
deploy:
|
8
|
+
provider: rubygems
|
9
|
+
api_key:
|
10
|
+
secure: ahAeEGLzp7Y3lPGTmPC1UeuVkE8WwBmdDu7JXm9Hf5FRc3AIQgf+eEFB+M6jDqithbA5kyC59UwsP/tohwBGRFwPpFrxgFT4dKxjgzec+wR2jlEcoFqUzc9Tug2IHBLIMMhK1Vo7FPJJ3J0Fho+VDlOYnG9nV69Lhf9A82BAPtQ=
|
11
|
+
gem: wordref
|
12
|
+
on:
|
13
|
+
tags: true
|
14
|
+
repo: pcboy/wordref
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Wordref
|
6
6
|
|
7
7
|
Wordref is a tiny gem to get a translation from Word reference (no API key needed).
|
8
|
-
You can translate words from one language to another (
|
8
|
+
You can translate words from one language to another ([Wordreference supported languages](https://github.com/pcboy/wordref/commit/25b4a4fef89e40cce6ae018501041aa6584538d8#diff-43114cec6cc4579b1d10b1d75031e5b5R52))
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
data/lib/wordref.rb
CHANGED
@@ -23,12 +23,19 @@ require 'attempt'
|
|
23
23
|
require 'nokogiri'
|
24
24
|
|
25
25
|
module Wordref
|
26
|
-
|
27
26
|
class Wordref
|
27
|
+
class InvalidLangFormat < ArgumentError; end;
|
28
|
+
|
28
29
|
def translate(params = {})
|
30
|
+
if !accepted_langs.keys.include?(params[:from] + params[:to])
|
31
|
+
raise InvalidLangFormat,
|
32
|
+
"Invalid chosen language (#{params[:from]} / #{params[:to]}).\n" +
|
33
|
+
"Accepted langs are:\n" + accepted_langs.to_s
|
34
|
+
end
|
35
|
+
|
29
36
|
dic = "#{params[:from] || 'en'}#{params[:to]}"
|
30
37
|
word = params[:word]
|
31
|
-
|
38
|
+
|
32
39
|
response = attempt(3, 3) {
|
33
40
|
open("http://www.wordreference.com/#{dic}/#{URI::encode(word)}",
|
34
41
|
'User-Agent' => 'Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0').read
|
@@ -38,6 +45,48 @@ module Wordref
|
|
38
45
|
return nil if first_trans.nil?
|
39
46
|
first_trans.css('td[class="ToWrd"] > text()').to_s.strip
|
40
47
|
end
|
41
|
-
end
|
42
48
|
|
49
|
+
private
|
50
|
+
def accepted_langs
|
51
|
+
{
|
52
|
+
"enes" => "English-Spanish",
|
53
|
+
"esen" => "Spanish-English",
|
54
|
+
"esfr" => "Spanish-French",
|
55
|
+
"espt" => "Spanish-Portuguese",
|
56
|
+
"enfr" => "English-French",
|
57
|
+
"fren" => "French-English",
|
58
|
+
"fres" => "French-Spanish",
|
59
|
+
"enit" => "English-Italian",
|
60
|
+
"iten" => "Italian-English",
|
61
|
+
"ende" => "English-German",
|
62
|
+
"deen" => "German-English",
|
63
|
+
"ensv" => "English-Swedish",
|
64
|
+
"sven" => "Swedish-English",
|
65
|
+
"enru" => "English-Russian",
|
66
|
+
"ruen" => "Russian-English",
|
67
|
+
"enpt" => "English-Portuguese",
|
68
|
+
"pten" => "Portuguese-English",
|
69
|
+
"ptes" => "Portuguese-Spanish",
|
70
|
+
"enpl" => "English-Polish",
|
71
|
+
"plen" => "Polish-English",
|
72
|
+
"enro" => "English-Romanian",
|
73
|
+
"roen" => "Romanian-English",
|
74
|
+
"encz" => "English-Czech",
|
75
|
+
"czen" => "Czech-English",
|
76
|
+
"engr" => "English-Greek",
|
77
|
+
"gren" => "Greek-English",
|
78
|
+
"entr" => "English-Turkish",
|
79
|
+
"tren" => "Turkish-English",
|
80
|
+
"enzh" => "English-Chinese",
|
81
|
+
"zhen" => "Chinese-English",
|
82
|
+
"enja" => "English-Japanese",
|
83
|
+
"jaen" => "Japanese-English",
|
84
|
+
"enko" => "English-Korean",
|
85
|
+
"koen" => "Korean-English",
|
86
|
+
"enar" => "English-Arabic",
|
87
|
+
"aren" => "Arabic-English"
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
43
92
|
end
|
data/lib/wordref/version.rb
CHANGED
data/spec/lib/wordref_spec.rb
CHANGED
@@ -23,4 +23,10 @@ describe Wordref do
|
|
23
23
|
tr = Wordref::Wordref.new
|
24
24
|
expect(tr.translate(from: 'en', to: 'fr', word: 'car')).to eq("voiture")
|
25
25
|
end
|
26
|
+
|
27
|
+
it "should throw an error if chosen language is incorrect" do
|
28
|
+
expect {
|
29
|
+
Wordref::Wordref.new.translate(from: 'english', to: 'french', word: 'car')
|
30
|
+
}.to raise_error(Wordref::Wordref::InvalidLangFormat)
|
31
|
+
end
|
26
32
|
end
|
data/wordref.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["david.hagege@gmail.com"]
|
11
11
|
gem.description = %q{Tiny gem to translate words with the WordReference API}
|
12
12
|
gem.summary = ""
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "https://github.com/pcboy/rtatoeba"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wordref
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pcboy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -84,7 +84,7 @@ files:
|
|
84
84
|
- spec/lib/wordref_spec.rb
|
85
85
|
- spec/spec_helper.rb
|
86
86
|
- wordref.gemspec
|
87
|
-
homepage:
|
87
|
+
homepage: https://github.com/pcboy/rtatoeba
|
88
88
|
licenses: []
|
89
89
|
metadata: {}
|
90
90
|
post_install_message:
|
@@ -103,11 +103,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.4.
|
106
|
+
rubygems_version: 2.4.5
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: ''
|
110
110
|
test_files:
|
111
111
|
- spec/lib/wordref_spec.rb
|
112
112
|
- spec/spec_helper.rb
|
113
|
-
has_rdoc:
|