Class: Babelyoda::LocalizationKey
- Inherits:
-
Object
- Object
- Babelyoda::LocalizationKey
- Defined in:
- lib/babelyoda/tanker.rb,
lib/babelyoda/localization_key.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(localization_value) ⇒ Object
- #drop_empty! ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(id, context) ⇒ LocalizationKey
constructor
A new instance of LocalizationKey.
- #merge!(localization_key, options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(id, context) ⇒ LocalizationKey
Returns a new instance of LocalizationKey.
7 8 9 10 11 |
# File 'lib/babelyoda/localization_key.rb', line 7 def initialize(id, context) @id = id @context = context @values = {} end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/babelyoda/localization_key.rb', line 4 def context @context end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/babelyoda/localization_key.rb', line 3 def id @id end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
5 6 7 |
# File 'lib/babelyoda/localization_key.rb', line 5 def values @values end |
Class Method Details
.parse_xml(node) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/babelyoda/tanker.rb', line 35 def self.parse_xml(node) context = node.css('context').first context &&= context.text result = self.new(node[:id], context) node.css('value').each do |value_node| value = Babelyoda::LocalizationValue.parse_xml(value_node) result << value if value end result end |
Instance Method Details
#<<(localization_value) ⇒ Object
17 18 19 20 |
# File 'lib/babelyoda/localization_key.rb', line 17 def <<(localization_value) @values[localization_value.language.to_sym] = localization_value.dup self end |
#drop_empty! ⇒ Object
50 51 52 53 54 |
# File 'lib/babelyoda/localization_key.rb', line 50 def drop_empty! @values.delete_if do |id, value| value.text.empty? end end |
#empty? ⇒ Boolean
56 57 58 |
# File 'lib/babelyoda/localization_key.rb', line 56 def empty? @values.empty? end |
#merge!(localization_key, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/babelyoda/localization_key.rb', line 22 def merge!(localization_key, = {}) updated = false context_changed = false if @context != localization_key.context @context = localization_key.context updated = context_changed = true end localization_key.values.each_value do |value| if @values.has_key?(value.language.to_sym) updated = true if @values[value.language.to_sym].merge!(value, ) else @values[value.language.to_sym] = value.dup updated = true end end # Mark all values as requiring translation if the context has changed. if context_changed @values.each_value do |value| value.status = :requires_translation end end return updated end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/babelyoda/localization_key.rb', line 13 def to_s "\"#{@id}\" [#{@values.keys.map{|k| ":#{k.to_s}"}.join(', ')}] // #{@context}" end |