Class: Translatomatic::Translation::Result
- Inherits:
-
Object
- Object
- Translatomatic::Translation::Result
- Defined in:
- lib/translatomatic/translation/result.rb
Overview
Data object describing a text translation
Instance Attribute Summary collapse
-
#from_database ⇒ boolean
readonly
True if this translation came from the database.
-
#original ⇒ Translatomatic::Text
readonly
Original string.
-
#provider ⇒ Symbol
readonly
The name of the provider.
-
#result ⇒ Translatomatic::Text
readonly
Translated string.
Instance Method Summary collapse
-
#description ⇒ String
A description of this translation.
-
#initialize(original, result, provider, options = {}) ⇒ Result
constructor
A new instance of Result.
-
#to_s ⇒ String
The translated string.
Constructor Details
#initialize(original, result, provider, options = {}) ⇒ Result
Returns a new instance of Result.
18 19 20 21 22 23 24 25 |
# File 'lib/translatomatic/translation/result.rb', line 18 def initialize(original, result, provider, = {}) raise 'original required' unless original.present? raise 'result required' unless result.present? @original = build_text(original) @result = build_text(result) @provider = provider @from_database = [:from_database] end |
Instance Attribute Details
#from_database ⇒ boolean (readonly)
Returns True if this translation came from the database.
16 17 18 |
# File 'lib/translatomatic/translation/result.rb', line 16 def from_database @from_database end |
#original ⇒ Translatomatic::Text (readonly)
Returns original string.
6 7 8 |
# File 'lib/translatomatic/translation/result.rb', line 6 def original @original end |
#provider ⇒ Symbol (readonly)
Returns The name of the provider. Can be nil for translations that have been reconstituted from substrings.
13 14 15 |
# File 'lib/translatomatic/translation/result.rb', line 13 def provider @provider end |
#result ⇒ Translatomatic::Text (readonly)
Returns translated string.
9 10 11 |
# File 'lib/translatomatic/translation/result.rb', line 9 def result @result end |
Instance Method Details
#description ⇒ String
Returns A description of this translation.
33 34 35 36 37 |
# File 'lib/translatomatic/translation/result.rb', line 33 def description format('%<original>s (%<from_locale>s) -> %<result>s (%<to_locale>s)', original: original.to_s, result: result.to_s, from_locale: original.locale, to_locale: result.locale) end |
#to_s ⇒ String
Returns The translated string.
28 29 30 |
# File 'lib/translatomatic/translation/result.rb', line 28 def to_s result.to_s end |