rufregle 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rufregle.rb +34 -14
  3. metadata +3 -4
  4. data/lib/helper/webhelper.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f06e6e84f18a7567e132b714c4aab615f092a4e1
4
- data.tar.gz: d6a2225db918656a25fccb30578d69eb781d9666
3
+ metadata.gz: c0ffae5d9fd86035d97d6b0c7affb935d2a77e05
4
+ data.tar.gz: f62cf5cf8beecdd384a0da1beb4f8bcffbb1c64d
5
5
  SHA512:
6
- metadata.gz: 5e9bcc4ec84f830b1cdc15af251a4424988e8eb81387977c8d41391816bb24c5eff1a22addbaca6979986d79907614d9b9429d9ee18080444560482176c71ee2
7
- data.tar.gz: 9f086559b60b75a04e73b89f2575f4d9e1444d443056718419943eb7a7a2535cfaa92e175c0a8e57e23fca4416792d0bb0473f5af1e3175742a5004247a397ef
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
- raw_translated = WebHelper.acess_url(url)
16
-
17
- raw_translated = raw_translated.force_encoding('utf-8')
18
-
19
- text_hash = raw_translated.scan(/\"(.*?)\"/).to_a
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
- require_relative 'helper/webhelper.rb'
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.1
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-translate
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.2.2
40
+ rubygems_version: 2.4.5
42
41
  signing_key:
43
42
  specification_version: 4
44
43
  summary: Free google translate!
@@ -1,12 +0,0 @@
1
- require 'net/http'
2
-
3
- class WebHelper
4
- def initialize(language = "english")
5
- @language = language
6
- end
7
-
8
- def self.acess_url(url)
9
- response = Net::HTTP.get(URI.parse(url))
10
- response
11
- end
12
- end