Class: Babelyoda::LocalizationValue

Inherits:
Object
  • Object
show all
Defined in:
lib/babelyoda/tanker.rb,
lib/babelyoda/localization_value.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language, text, status = :requires_translation) ⇒ LocalizationValue

Returns a new instance of LocalizationValue.



7
8
9
# File 'lib/babelyoda/localization_value.rb', line 7

def initialize(language, text, status = :requires_translation)
  @language, @text, @status = language.to_sym, text, status.to_sym
end

Instance Attribute Details

#languageObject

Returns the value of attribute language.



3
4
5
# File 'lib/babelyoda/localization_value.rb', line 3

def language
  @language
end

#statusObject

Returns the value of attribute status.



4
5
6
# File 'lib/babelyoda/localization_value.rb', line 4

def status
  @status
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/babelyoda/localization_value.rb', line 5

def text
  @text
end

Class Method Details

.parse_xml(node) ⇒ Object



48
49
50
51
52
# File 'lib/babelyoda/tanker.rb', line 48

def self.parse_xml(node)
  if node.text.length > 0
    self.new(node[:language], node.text, node[:status])
  end
end

Instance Method Details

#merge!(other_value, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/babelyoda/localization_value.rb', line 11

def merge!(other_value, options = {})
  updated = false
  options = { preserve: false }.merge!(options)
  unless @language.to_sym == other_value.language.to_sym
    raise RuntimeError.new("Can't merge values in different languages: #{@language.to_sym} and #{other_value.language.to_sym}") 
  end
  if (!options[:preserve] || @status.to_sym == :requires_translation)
    unless @text == other_value.text
      @text = other_value.text 
      updated = true
    end
  end
  return updated
end