Class: ZLocalize::TranslationEntryCollection
- Inherits:
-
Hash
- Object
- Hash
- ZLocalize::TranslationEntryCollection
- Defined in:
- lib/zlocalize/translation_file.rb
Overview
:nodoc: all
Instance Method Summary collapse
- #add_entry(key, ref) ⇒ Object
-
#sort_by_id ⇒ Object
return an Array of entries, sorted by id.
- #synchronize_with(collection, purge = false) ⇒ Object
Instance Method Details
#add_entry(key, ref) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/zlocalize/translation_file.rb', line 99 def add_entry(key,ref) if entry = self[key] entry.add_reference(ref) else entry = TranslationEntry.new(:source => key, :references => [ref], :translation => nil) self[key] = entry end entry end |
#sort_by_id ⇒ Object
return an Array of entries, sorted by id
125 126 127 128 |
# File 'lib/zlocalize/translation_file.rb', line 125 def sort_by_id # Hash#sort will convert each item to an Array of 2 elements [key, value] sort { |entry1,entry2| entry1[1].id.to_i <=> entry2[1].id.to_i }.collect { |el| el[1] } end |
#synchronize_with(collection, purge = false) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/zlocalize/translation_file.rb', line 109 def synchronize_with(collection, purge = false) if purge # first, remove our entries that are not present in the other collection self.delete_if { |key,entry| !collection.key?(key) } end # add entries from the other collection that are not already in this collection collection.each do |key,entry| if self.key?(key) self[key].synchronize_references(entry) else self[key] = entry end end end |