rufregle 1.0.2 → 2.0.0

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 +27 -20
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71fd8998ffc39752ad578bed3e18aad885e328b3
4
- data.tar.gz: 9b103b50a86d74a132c2341132bd92e5207b7ee2
3
+ metadata.gz: 8d01902f91959c64ce0f3334d38da418dd33c1c4
4
+ data.tar.gz: 7a0f370388656346b1f2964b41012f2235dfa2fa
5
5
  SHA512:
6
- metadata.gz: 40bd70aeb49b3a92e2f5ad7b89898c277e04f69b62ff133b36a9c7915d9b6e916dd3a9a80371480acfafcaa669b85a2ea638a53f39fbad473b140789c0718009
7
- data.tar.gz: eb91cad82c066139c4f8376a082f98febca060d1305066539d4824ed906e3add39a589f5b12d88dedf72ba9da004e1a3c84e316b24f31240110e2f5316d7ff35
6
+ metadata.gz: 80b1931f5988d83ec52ad52e0462f17822f77e4c0229c8afbdd3ade3cc6f97a0f47c6b89e4e6a0fae912b9809d46436b084989e04ce19d5194b30b0f820b0556
7
+ data.tar.gz: 865292ad80b24d9e16e2b041c19e67e26a3e8e101f556bdc9fa4aec95761470559b136a8ca1e4fe1507f18aaf41ed55ed33a372edfef40757697f3be908b4427
data/lib/rufregle.rb CHANGED
@@ -1,28 +1,35 @@
1
- require './lib/translators/free_google_translator.rb'
2
-
1
+ require_relative 'translators/free_google/factory'
2
+ ##
3
+ # Rufregle is a client api for translations
4
+ # it uses as default {FreeGoogle::Translator}
5
+ #
3
6
  class Rufregle
7
+ attr_writer :translator
4
8
 
5
- @@translator
6
-
7
- def translator=(translator)
8
- @@translator = translator
9
- end
10
-
11
- def translate(text, from_language, to_language)
12
-
13
- validate_params([text, from_language, to_language])
14
- translator.do_translate text, from_language, to_language
15
-
9
+ def initialize()
10
+ @translator = FreeGoogle::Factory.create()
16
11
  end
17
12
 
18
- private
19
- def translator
20
- @@translator ||= FreeGoogleTranslator.new
13
+ ##
14
+ # Return a translated text of a given +text+ +from+ language +to+ another language
15
+ #
16
+ # See language codes on {http://sites.google.com/site/tomihasa/google-language-codes}
17
+ #
18
+ # @param text [String] Text to be translated.
19
+ # @param from [String] Language code of text
20
+ # @param to [String] Language code to be translate
21
+ # @raise Error unless all params informed
22
+ # @return [Hash] translated text and the original text from.
23
+ # Example:
24
+ # { translated: "Ola mundo", original: "Hello word" }
25
+
26
+ def translate(text, from, to)
27
+ raise 'Rufregle: All params must be informed' unless all_present?([text, from, to])
28
+ @translator.translate(text, from, to)
21
29
  end
22
30
 
23
- def validate_params(params)
24
- if !params.map{ |p| p.nil? || p.empty? }
25
- raise 'Rufregle: All params must be informed'
26
- end
31
+ def all_present?(params)
32
+ params.each {|val| return false if val.nil? || val.empty? }
33
+ return true
27
34
  end
28
35
  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: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristian Oliveira
@@ -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.2.2
40
+ rubygems_version: 2.4.6
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: Free google translate!