rufregle 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 +4 -4
- data/lib/rufregle.rb +34 -14
- metadata +3 -4
- data/lib/helper/webhelper.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0ffae5d9fd86035d97d6b0c7affb935d2a77e05
|
4
|
+
data.tar.gz: f62cf5cf8beecdd384a0da1beb4f8bcffbb1c64d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffe3879b0f7cd13a72995145b35c6f6601108e81e8ae0fc1dc15f6c46f2179cee1ba8b57bbcfb2b713c74d02a4b975856132437517df790daae829042fd0b97f
|
7
|
+
data.tar.gz: ddd75fe0cb182ad4d76a71f7a823dd99d062fe87f6dd4e5c6a509708b32503cb8825e2a6db0eeab6d5de65e4a26c7e2dec4e7fa2f0f07eaa8cd81e9072f22528
|
data/lib/rufregle.rb
CHANGED
@@ -1,25 +1,45 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
|
3
3
|
class Rufregle
|
4
|
-
|
4
|
+
|
5
5
|
GOOGLE_URL_API = "http://translate.google.com/translate_a/"
|
6
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"
|
7
7
|
|
8
|
+
@cachedTranslate
|
9
|
+
|
10
|
+
def translate_and_cache(text_to_translate, language_from, language_to)
|
11
|
+
@cachedTranslate = Rufregle.translate()
|
12
|
+
|
13
|
+
@cachedTranslate
|
14
|
+
end
|
15
|
+
|
8
16
|
def self.translate(text_to_translate, language_from, language_to)
|
9
|
-
|
17
|
+
|
10
18
|
text_encoded = URI::encode(text_to_translate)
|
11
|
-
|
19
|
+
|
12
20
|
parameters = GOOGLE_PARAMS % [ text_encoded , language_from, language_from, language_to ]
|
13
|
-
url = GOOGLE_URL_API << parameters
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
text_hash
|
21
|
+
url = GOOGLE_URL_API << parameters
|
22
|
+
|
23
|
+
raw_data = Net::HTTP.get(URI.parse(url))
|
24
|
+
|
25
|
+
data = cast_raw_data(raw_data)
|
26
|
+
|
27
|
+
data.first
|
28
|
+
|
22
29
|
end
|
23
|
-
end
|
24
30
|
|
25
|
-
|
31
|
+
def get_cached_translate
|
32
|
+
@cachedTranslate
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def cast_raw_data(data)
|
37
|
+
|
38
|
+
data = data.force_encoding('utf-8')
|
39
|
+
|
40
|
+
data = data.scan(/\"(.*?)\"/).to_a
|
41
|
+
|
42
|
+
data.first
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rufregle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cristian Oliveira
|
@@ -16,9 +16,8 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- lib/helper/webhelper.rb
|
20
19
|
- lib/rufregle.rb
|
21
|
-
homepage: https://github.com/CristianOliveiraDaRosa/rufregle
|
20
|
+
homepage: https://github.com/CristianOliveiraDaRosa/rufregle
|
22
21
|
licenses:
|
23
22
|
- MIT
|
24
23
|
metadata: {}
|
@@ -38,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
37
|
version: '0'
|
39
38
|
requirements: []
|
40
39
|
rubyforge_project:
|
41
|
-
rubygems_version: 2.
|
40
|
+
rubygems_version: 2.4.5
|
42
41
|
signing_key:
|
43
42
|
specification_version: 4
|
44
43
|
summary: Free google translate!
|