Class: Translator::Translate
- Inherits:
-
Object
- Object
- Translator::Translate
- Includes:
- PoltergeistConfig
- Defined in:
- lib/translator.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
-
#initialize(string, to: '', from: '') ⇒ Translate
constructor
A new instance of Translate.
- #parsed_string ⇒ Object
- #result ⇒ Object
- #translate! ⇒ Object
- #visit_google_translator ⇒ Object
Constructor Details
#initialize(string, to: '', from: '') ⇒ Translate
Returns a new instance of Translate.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/translator.rb', line 13 def initialize(string, to: '', from: '') @string = string @to = to @from = from if to.empty? && from.empty? @to = Translator::ConfigFile.default_to || 'auto' @from = Translator::ConfigFile.default_from end end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
11 12 13 |
# File 'lib/translator.rb', line 11 def from @from end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
10 11 12 |
# File 'lib/translator.rb', line 10 def string @string end |
#to ⇒ Object
Returns the value of attribute to.
11 12 13 |
# File 'lib/translator.rb', line 11 def to @to end |
Instance Method Details
#parsed_string ⇒ Object
40 41 42 |
# File 'lib/translator.rb', line 40 def parsed_string string.split(' ').join('%20') end |
#result ⇒ Object
32 33 34 |
# File 'lib/translator.rb', line 32 def result find('#result_box').text end |
#translate! ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/translator.rb', line 24 def translate! visit_google_translator sleep 3 result.colorize(:light_green) end |
#visit_google_translator ⇒ Object
36 37 38 |
# File 'lib/translator.rb', line 36 def visit_google_translator visit "https://translate.google.com.br/?source=osdd##{from}/#{to}/#{parsed_string}" end |