rufregle 0.0.2 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rufregle.rb +14 -31
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0ffae5d9fd86035d97d6b0c7affb935d2a77e05
4
- data.tar.gz: f62cf5cf8beecdd384a0da1beb4f8bcffbb1c64d
3
+ metadata.gz: 71fd8998ffc39752ad578bed3e18aad885e328b3
4
+ data.tar.gz: 9b103b50a86d74a132c2341132bd92e5207b7ee2
5
5
  SHA512:
6
- metadata.gz: ffe3879b0f7cd13a72995145b35c6f6601108e81e8ae0fc1dc15f6c46f2179cee1ba8b57bbcfb2b713c74d02a4b975856132437517df790daae829042fd0b97f
7
- data.tar.gz: ddd75fe0cb182ad4d76a71f7a823dd99d062fe87f6dd4e5c6a509708b32503cb8825e2a6db0eeab6d5de65e4a26c7e2dec4e7fa2f0f07eaa8cd81e9072f22528
6
+ metadata.gz: 40bd70aeb49b3a92e2f5ad7b89898c277e04f69b62ff133b36a9c7915d9b6e916dd3a9a80371480acfafcaa669b85a2ea638a53f39fbad473b140789c0718009
7
+ data.tar.gz: eb91cad82c066139c4f8376a082f98febca060d1305066539d4824ed906e3add39a589f5b12d88dedf72ba9da004e1a3c84e316b24f31240110e2f5316d7ff35
data/lib/rufregle.rb CHANGED
@@ -1,45 +1,28 @@
1
- require 'open-uri'
1
+ require './lib/translators/free_google_translator.rb'
2
2
 
3
3
  class Rufregle
4
4
 
5
- GOOGLE_URL_API = "http://translate.google.com/translate_a/"
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
- @cachedTranslate
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 self.translate(text_to_translate, language_from, language_to)
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
- data.first
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 cast_raw_data(data)
37
-
38
- data = data.force_encoding('utf-8')
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: 0.0.2
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: 2013-04-28 00:00:00.000000000 Z
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.4.5
40
+ rubygems_version: 2.2.2
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: Free google translate!