Class: MiHermano
- Inherits:
-
Object
- Object
- MiHermano
- Defined in:
- lib/mi_hermano.rb,
lib/mi_hermano/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attrs) ⇒ MiHermano
constructor
A new instance of MiHermano.
- #translate(text, source = nil, target = nil) ⇒ Object
Constructor Details
#initialize(attrs) ⇒ MiHermano
Returns a new instance of MiHermano.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mi_hermano.rb', line 13 def initialize(attrs) @spreadsheet_key = attrs[:spreadsheet_key] @username = attrs[:username] @password = attrs[:password] @default_source = attrs[:default_source] || :en @default_target = attrs[:default_target] || :fr @session = GoogleSpreadsheet.login(@username, @password) @worksheet = @session.spreadsheet_by_key(@spreadsheet_key).worksheets[0] end |
Class Method Details
.setup(attrs) ⇒ Object
5 6 7 |
# File 'lib/mi_hermano.rb', line 5 def self.setup(attrs) @@default = new(attrs) end |
.translate(text, source = nil, target = nil) ⇒ Object
9 10 11 |
# File 'lib/mi_hermano.rb', line 9 def self.translate(text, source=nil, target=nil) @@default.translate(text, source, target) end |
Instance Method Details
#translate(text, source = nil, target = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/mi_hermano.rb', line 24 def translate(text, source=nil, target=nil) source ||= @default_source target ||= @default_target @worksheet[1, 1] = '=GoogleTranslate("'+text+'"; "'+source.to_s+'"; "'+target.to_s+'")' @worksheet.save @worksheet.reload @worksheet[1, 1] end |