rufregle 0.0.2 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rufregle.rb +14 -31
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71fd8998ffc39752ad578bed3e18aad885e328b3
|
4
|
+
data.tar.gz: 9b103b50a86d74a132c2341132bd92e5207b7ee2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40bd70aeb49b3a92e2f5ad7b89898c277e04f69b62ff133b36a9c7915d9b6e916dd3a9a80371480acfafcaa669b85a2ea638a53f39fbad473b140789c0718009
|
7
|
+
data.tar.gz: eb91cad82c066139c4f8376a082f98febca060d1305066539d4824ed906e3add39a589f5b12d88dedf72ba9da004e1a3c84e316b24f31240110e2f5316d7ff35
|
data/lib/rufregle.rb
CHANGED
@@ -1,45 +1,28 @@
|
|
1
|
-
require '
|
1
|
+
require './lib/translators/free_google_translator.rb'
|
2
2
|
|
3
3
|
class Rufregle
|
4
4
|
|
5
|
-
|
6
|
-
GOOGLE_PARAMS = "t?client=t&text=%s&hl=%s&sl=%s&tl=%s&ie=UTF-8&oe=UTF-8&multires=1&otf=1&ssel=3&tsel=3&sc=1"
|
5
|
+
@@translator
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
def translate_and_cache(text_to_translate, language_from, language_to)
|
11
|
-
@cachedTranslate = Rufregle.translate()
|
12
|
-
|
13
|
-
@cachedTranslate
|
7
|
+
def translator=(translator)
|
8
|
+
@@translator = translator
|
14
9
|
end
|
15
10
|
|
16
|
-
def
|
17
|
-
|
18
|
-
text_encoded = URI::encode(text_to_translate)
|
19
|
-
|
20
|
-
parameters = GOOGLE_PARAMS % [ text_encoded , language_from, language_from, language_to ]
|
21
|
-
url = GOOGLE_URL_API << parameters
|
22
|
-
|
23
|
-
raw_data = Net::HTTP.get(URI.parse(url))
|
24
|
-
|
25
|
-
data = cast_raw_data(raw_data)
|
11
|
+
def translate(text, from_language, to_language)
|
26
12
|
|
27
|
-
|
13
|
+
validate_params([text, from_language, to_language])
|
14
|
+
translator.do_translate text, from_language, to_language
|
28
15
|
|
29
16
|
end
|
30
17
|
|
31
|
-
def get_cached_translate
|
32
|
-
@cachedTranslate
|
33
|
-
end
|
34
|
-
|
35
18
|
private
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
data = data.scan(/\"(.*?)\"/).to_a
|
41
|
-
|
42
|
-
data.first
|
19
|
+
def translator
|
20
|
+
@@translator ||= FreeGoogleTranslator.new
|
21
|
+
end
|
43
22
|
|
23
|
+
def validate_params(params)
|
24
|
+
if !params.map{ |p| p.nil? || p.empty? }
|
25
|
+
raise 'Rufregle: All params must be informed'
|
26
|
+
end
|
44
27
|
end
|
45
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rufregle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cristian Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Simple Free google translate.
|
14
14
|
email: contato@cristianoliveira.com.br
|
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
39
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.
|
40
|
+
rubygems_version: 2.2.2
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
43
|
summary: Free google translate!
|