wordref 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a66711a2b2e83bc60ffd8c21bd2cb3c5d24c0baa
4
- data.tar.gz: b9d336cf87765b902c1beeaecd59c49d49b4128f
3
+ metadata.gz: dbfa8fd138bc5b2d81e9b40fa8a342182ceca80a
4
+ data.tar.gz: 623d1170651c9fc430d6084d7b5f4e7e865ba53d
5
5
  SHA512:
6
- metadata.gz: 35fa00278ac5ee5a98ed3303c18bbfdd49fe355597fc69720da4812d6da12dead5d066fb8e4aac526cd7880e367b6ad106992ad966b027e264807343ee55e4cd
7
- data.tar.gz: 99c09185f264d45ccebde8d77566ac0a06b57ff7062e17851240ae537c5aebcb4ace926ca66fd53b4e7ef594354b7732a5dcddfbb285a365724cc538e8d7ae70
6
+ metadata.gz: e2b65845fed09c0068a119cbfe034c71303d6224d247482c0f1f21501449d3f4d8ad09855f1ff153fd5f78e155f276007735df3a86bd591cb7357e55ce8ec4ca
7
+ data.tar.gz: 3a2f8e7e64fd1d73bb779b6ccdb54d0f768e1f7bec28ed8c5e2aa88010dd63ce5bdb9ea65609b6bcb890657acb2bd28b3b7b6421f7818f6e969f379f22b3af15
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 1.9.2
5
+ - jruby-19mode
6
+ script: rake
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
+ [![Build Status](https://travis-ci.org/pcboy/wordref.svg)](https://travis-ci.org/pcboy/wordref)
2
+ [![Gem Version](https://badge.fury.io/rb/wordref.svg)](http://badge.fury.io/rb/wordref)
3
+
1
4
  # Wordref
2
5
 
3
- Wordref is a tiny wrapper for the WordReference API.
6
+ Wordref is a tiny gem to get a translation from Word reference (no API key needed).
4
7
  You can translate words from one language to another (Note that Wordreference only supports FROM English and TO english translations)
5
8
 
6
9
  ## Installation
@@ -19,9 +22,9 @@ Or install it yourself as:
19
22
 
20
23
  ## Usage
21
24
 
22
- wr = Wordref::Wordref.new('your_api_key')
25
+ wr = Wordref::Wordref.new
23
26
 
24
- wr.translate(from: 'en', to: 'fr', 'cat') # => "chat"
27
+ wr.translate(from: 'en', to: 'fr', word: 'cat') # => "chat"
25
28
 
26
29
  If you don't give the "from" parameter it'll automatically be set to english.
27
30
  That's all.
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
8
+
@@ -20,26 +20,21 @@ require "wordref/version"
20
20
  require 'open-uri'
21
21
  require 'multi_json'
22
22
  require 'attempt'
23
+ require 'nokogiri'
23
24
 
24
25
  module Wordref
25
26
 
26
27
  class Wordref
27
- def initialize(api_key)
28
- @api_key = api_key
29
- end
30
-
31
28
  def translate(params = {})
32
29
  dic = "#{params[:from] || 'en'}#{params[:to]}"
33
30
  word = params[:word]
34
31
 
35
32
  response = attempt(3, 3) {
36
- open("http://api.wordreference.com/#{@api_key}/json/#{dic}/#{URI::encode(word)}").read
33
+ open("http://www.wordreference.com/#{dic}/#{URI::encode(word)}").read
37
34
  }
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']
35
+ doc = Nokogiri::HTML(response)
36
+ first_trans = doc.css("tr[id^='#{dic}:']").first
37
+ first_trans.css('td[class="ToWrd"] > text()').to_s.strip
43
38
  end
44
39
  end
45
40
 
@@ -1,3 +1,3 @@
1
1
  module Wordref
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -20,7 +20,7 @@ require 'wordref'
20
20
 
21
21
  describe Wordref do
22
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")
23
+ tr = Wordref::Wordref.new
24
+ expect(tr.translate(from: 'en', to: 'fr', word: 'car')).to eq("voiture")
25
25
  end
26
26
  end
@@ -0,0 +1,19 @@
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'
@@ -18,5 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
  gem.add_dependency "multi_json"
20
20
  gem.add_dependency "attempt"
21
+ gem.add_dependency "nokogiri"
21
22
  gem.add_development_dependency "rspec"
22
23
  end
metadata CHANGED
@@ -1,55 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordref
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pcboy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-17 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: attempt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - '>='
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
61
  version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - '>='
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  description: Tiny gem to translate words with the WordReference API
@@ -59,14 +73,16 @@ executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
- - .gitignore
76
+ - ".gitignore"
77
+ - ".travis.yml"
63
78
  - Gemfile
64
79
  - LICENSE.txt
65
80
  - README.md
66
81
  - Rakefile
67
82
  - lib/wordref.rb
68
83
  - lib/wordref/version.rb
69
- - spec/wordref_spec.rb
84
+ - spec/lib/wordref_spec.rb
85
+ - spec/spec_helper.rb
70
86
  - wordref.gemspec
71
87
  homepage: ''
72
88
  licenses: []
@@ -77,19 +93,21 @@ require_paths:
77
93
  - lib
78
94
  required_ruby_version: !ruby/object:Gem::Requirement
79
95
  requirements:
80
- - - '>='
96
+ - - ">="
81
97
  - !ruby/object:Gem::Version
82
98
  version: '0'
83
99
  required_rubygems_version: !ruby/object:Gem::Requirement
84
100
  requirements:
85
- - - '>='
101
+ - - ">="
86
102
  - !ruby/object:Gem::Version
87
103
  version: '0'
88
104
  requirements: []
89
105
  rubyforge_project:
90
- rubygems_version: 2.0.3
106
+ rubygems_version: 2.4.6
91
107
  signing_key:
92
108
  specification_version: 4
93
109
  summary: ''
94
110
  test_files:
95
- - spec/wordref_spec.rb
111
+ - spec/lib/wordref_spec.rb
112
+ - spec/spec_helper.rb
113
+ has_rdoc: