rufregle 1.0.2 → 2.0.0
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 +27 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d01902f91959c64ce0f3334d38da418dd33c1c4
|
4
|
+
data.tar.gz: 7a0f370388656346b1f2964b41012f2235dfa2fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80b1931f5988d83ec52ad52e0462f17822f77e4c0229c8afbdd3ade3cc6f97a0f47c6b89e4e6a0fae912b9809d46436b084989e04ce19d5194b30b0f820b0556
|
7
|
+
data.tar.gz: 865292ad80b24d9e16e2b041c19e67e26a3e8e101f556bdc9fa4aec95761470559b136a8ca1e4fe1507f18aaf41ed55ed33a372edfef40757697f3be908b4427
|
data/lib/rufregle.rb
CHANGED
@@ -1,28 +1,35 @@
|
|
1
|
-
|
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
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
24
|
-
|
25
|
-
|
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:
|
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.
|
40
|
+
rubygems_version: 2.4.6
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
43
|
summary: Free google translate!
|