google_translate_scraper 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/README.md +10 -2
- data/Rakefile +4 -0
- data/google_translate_scraper.gemspec +2 -1
- data/lib/google_translate_scraper/translator.rb +1 -1
- data/lib/google_translate_scraper/version.rb +1 -1
- data/spec/google_translate_scraper_spec.rb +31 -0
- data/spec/spec_helper.rb +7 -0
- metadata +26 -7
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# GoogleTranslateScraper
|
2
2
|
|
3
|
-
|
3
|
+
This gem scraps GoogleTranslate and returns the translation for the given search phrase.
|
4
|
+
|
5
|
+
If multiple translations are available, multiple are returned.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -18,7 +20,13 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
1- require 'google_translate_scraper'
|
24
|
+
|
25
|
+
2- translator = GoogleTranslateScraper::Translator.new
|
26
|
+
|
27
|
+
3- translations = translations = translator.translate( source_language = "en", target_language = "sv", search_phrase = "sup fool" )
|
28
|
+
|
29
|
+
NOTE: source and target language values must be a string containg the ISO 639-1 letter code for that language. For a list see here: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
22
30
|
|
23
31
|
## Contributing
|
24
32
|
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/google_translate_scraper/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Seb Glazebrook"]
|
6
6
|
gem.email = ["me@sebglazebrook.com"]
|
7
|
-
gem.description = %q{"
|
7
|
+
gem.description = %q{"This gem scraps GoogleTranslate and returns the translation for the given search phrase. If multiple translations are available, multiple are returned."}
|
8
8
|
gem.summary = %q{"This gem scrapes Google Translate and their results."}
|
9
9
|
gem.homepage = ""
|
10
10
|
|
@@ -15,4 +15,5 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = GoogleTranslateScraper::VERSION
|
17
17
|
gem.add_dependency "nokogiri"
|
18
|
+
gem.add_development_dependency 'rspec', '~> 2.10.0'
|
18
19
|
end
|
@@ -55,7 +55,7 @@ require 'nokogiri'
|
|
55
55
|
|
56
56
|
# when there is a phrase with no dictionary translation i.e multiple possible translations
|
57
57
|
def get_non_dictionary_translation html_doc
|
58
|
-
translation = html_doc.xpath('
|
58
|
+
translation = html_doc.xpath('//*[@id="result_box"]/span')
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoogleTranslateScraper do
|
4
|
+
it 'should return an array' do
|
5
|
+
translator = GoogleTranslateScraper::Translator.new
|
6
|
+
results = translator.translate("en", "sv", "Hello")
|
7
|
+
results.should be_a_kind_of Array
|
8
|
+
end
|
9
|
+
|
10
|
+
# dictionary translations
|
11
|
+
it 'should return an array of Swedish translations for an English word' do
|
12
|
+
translator = GoogleTranslateScraper::Translator.new
|
13
|
+
results = translator.translate("en", "sv", "Hello")
|
14
|
+
results.size.should > 1
|
15
|
+
end
|
16
|
+
|
17
|
+
# non-dictinary translations
|
18
|
+
it 'should return a Swedish translations for a short English sentence' do
|
19
|
+
translator = GoogleTranslateScraper::Translator.new
|
20
|
+
results = translator.translate("en", "sv", "Hello there")
|
21
|
+
results.size.should eql 1
|
22
|
+
results[0].should eql"Hallå där"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return a Swedish translations for a long English sentence' do
|
26
|
+
translator = GoogleTranslateScraper::Translator.new
|
27
|
+
results = translator.translate("en","sv","Hi how are you? I'm good how are you?")
|
28
|
+
results.size.should eql 1
|
29
|
+
results[0].should eql"Hej hur mår du? Jag är bra hur mår du?"
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_translate_scraper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Seb Glazebrook
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-05-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: nokogiri
|
@@ -31,7 +31,23 @@ dependencies:
|
|
31
31
|
version: "0"
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
|
-
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 39
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 10
|
46
|
+
- 0
|
47
|
+
version: 2.10.0
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
description: "\"This gem scraps GoogleTranslate and returns the translation for the given search phrase. If multiple translations are available, multiple are returned.\""
|
35
51
|
email:
|
36
52
|
- me@sebglazebrook.com
|
37
53
|
executables: []
|
@@ -50,6 +66,8 @@ files:
|
|
50
66
|
- lib/google_translate_scraper.rb
|
51
67
|
- lib/google_translate_scraper/translator.rb
|
52
68
|
- lib/google_translate_scraper/version.rb
|
69
|
+
- spec/google_translate_scraper_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
53
71
|
homepage: ""
|
54
72
|
licenses: []
|
55
73
|
|
@@ -83,5 +101,6 @@ rubygems_version: 1.8.9
|
|
83
101
|
signing_key:
|
84
102
|
specification_version: 3
|
85
103
|
summary: "\"This gem scrapes Google Translate and their results.\""
|
86
|
-
test_files:
|
87
|
-
|
104
|
+
test_files:
|
105
|
+
- spec/google_translate_scraper_spec.rb
|
106
|
+
- spec/spec_helper.rb
|