Class: Gcloud::Translate::Translation
- Inherits:
-
Object
- Object
- Gcloud::Translate::Translation
- Defined in:
- lib/gcloud/translate/translation.rb
Overview
# Translation
Represents a translation query result. Returned by Api#translate.
Instance Attribute Summary collapse
-
#from ⇒ Object
(also: #source)
readonly
The source language from which the text was translated.
-
#origin ⇒ String
readonly
The original query text that was translated.
-
#text ⇒ String
(also: #to_s, #to_str)
readonly
The translated result.
-
#to ⇒ String
(also: #language, #target)
readonly
The target language into which the text was translated.
Class Method Summary collapse
-
.from_gapi(gapi, to, origin, from) ⇒ Object
by the Google API Client object.
-
.from_gapi_list(gapi, text, to, from) ⇒ Object
defined by the Google API Client object.
Instance Method Summary collapse
-
#detected? ⇒ Boolean
Determines if the source language was detected by the Google Cloud Translate API.
-
#initialize(text, to, origin, from, detected) ⇒ Translation
constructor
A new instance of Translation.
Constructor Details
#initialize(text, to, origin, from, detected) ⇒ Translation
Returns a new instance of Translation.
72 73 74 75 76 77 78 |
# File 'lib/gcloud/translate/translation.rb', line 72 def initialize text, to, origin, from, detected @text = text @to = to @origin = origin @from = from @detected = detected end |
Instance Attribute Details
#from ⇒ Object (readonly) Also known as: source
The source language from which the text was translated.
67 68 69 |
# File 'lib/gcloud/translate/translation.rb', line 67 def from @from end |
#origin ⇒ String (readonly)
The original query text that was translated.
55 56 57 |
# File 'lib/gcloud/translate/translation.rb', line 55 def origin @origin end |
#text ⇒ String (readonly) Also known as: to_s, to_str
The translated result.
47 48 49 |
# File 'lib/gcloud/translate/translation.rb', line 47 def text @text end |
#to ⇒ String (readonly) Also known as: language, target
The target language into which the text was translated.
61 62 63 |
# File 'lib/gcloud/translate/translation.rb', line 61 def to @to end |
Class Method Details
.from_gapi(gapi, to, origin, from) ⇒ Object
by the Google API Client object.
105 106 107 108 109 |
# File 'lib/gcloud/translate/translation.rb', line 105 def self.from_gapi gapi, to, origin, from from ||= gapi.detected_source_language detected = !gapi.detected_source_language.nil? new gapi.translated_text, to, origin, from, detected end |
.from_gapi_list(gapi, text, to, from) ⇒ Object
defined by the Google API Client object.
94 95 96 97 98 99 100 |
# File 'lib/gcloud/translate/translation.rb', line 94 def self.from_gapi_list gapi, text, to, from res = text.zip(Array(gapi.translations)).map do |origin, g| from_gapi g, to, origin, from end return res.first if res.size == 1 res end |
Instance Method Details
#detected? ⇒ Boolean
Determines if the source language was detected by the Google Cloud Translate API.
87 88 89 |
# File 'lib/gcloud/translate/translation.rb', line 87 def detected? @detected end |