Class: Lara::Models::TextResult

Inherits:
Base
  • Object
show all
Defined in:
lib/lara/models/text.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

parse_time

Constructor Details

#initialize(content_type:, source_language:, translation:, adapted_to: nil, glossaries: nil, adapted_to_matches: nil, glossaries_matches: nil, profanities: nil, styleguide_results: nil) ⇒ TextResult

Returns a new instance of TextResult.



184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/lara/models/text.rb', line 184

def initialize(content_type:, source_language:, translation:, adapted_to: nil, glossaries: nil,
               adapted_to_matches: nil, glossaries_matches: nil, profanities: nil,
               styleguide_results: nil)
  super()
  @content_type = content_type
  @source_language = source_language
  @translation = translation
  @adapted_to = adapted_to
  @glossaries = glossaries
  @adapted_to_matches = adapted_to_matches
  @glossaries_matches = glossaries_matches
  @profanities = profanities
  @styleguide_results = styleguide_results
end

Instance Attribute Details

#adapted_toObject (readonly)

Returns the value of attribute adapted_to.



150
151
152
# File 'lib/lara/models/text.rb', line 150

def adapted_to
  @adapted_to
end

#adapted_to_matchesObject (readonly)

Returns the value of attribute adapted_to_matches.



150
151
152
# File 'lib/lara/models/text.rb', line 150

def adapted_to_matches
  @adapted_to_matches
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



150
151
152
# File 'lib/lara/models/text.rb', line 150

def content_type
  @content_type
end

#glossariesObject (readonly)

Returns the value of attribute glossaries.



150
151
152
# File 'lib/lara/models/text.rb', line 150

def glossaries
  @glossaries
end

#glossaries_matchesObject (readonly)

Returns the value of attribute glossaries_matches.



150
151
152
# File 'lib/lara/models/text.rb', line 150

def glossaries_matches
  @glossaries_matches
end

#profanitiesObject (readonly)

Returns the value of attribute profanities.



150
151
152
# File 'lib/lara/models/text.rb', line 150

def profanities
  @profanities
end

#source_languageObject (readonly)

Returns the value of attribute source_language.



150
151
152
# File 'lib/lara/models/text.rb', line 150

def source_language
  @source_language
end

#styleguide_resultsObject (readonly)

Returns the value of attribute styleguide_results.



150
151
152
# File 'lib/lara/models/text.rb', line 150

def styleguide_results
  @styleguide_results
end

#translationObject (readonly)

Returns the value of attribute translation.



150
151
152
# File 'lib/lara/models/text.rb', line 150

def translation
  @translation
end

Class Method Details

.from_hash(hash) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/lara/models/text.rb', line 155

def self.from_hash(hash)
  return nil unless hash.is_a?(Hash)

  translation = hash["translation"]
  if translation.is_a?(Array) && translation.is_a?(Array) && !translation.all?(String)
    translation = translation.map do |e|
      TextBlock.new(text: e["text"],
                    translatable: e["translatable"])
    end
  end

  adapted_to_matches = convert_matches(hash["adapted_to_matches"], NGMemoryMatch)
  glossaries_matches = convert_matches(hash["glossaries_matches"], NGGlossaryMatch)
  profanities = convert_profanities(hash["profanities"])
  styleguide_results = convert_styleguide_results(hash["styleguide_results"])

  new(
    content_type: hash["content_type"],
    source_language: hash["source_language"],
    translation: translation,
    adapted_to: hash["adapted_to"],
    glossaries: hash["glossaries"],
    adapted_to_matches: adapted_to_matches,
    glossaries_matches: glossaries_matches,
    profanities: profanities,
    styleguide_results: styleguide_results
  )
end