Class: Locca::AndroidCollectionWriter
- Inherits:
-
Object
- Object
- Locca::AndroidCollectionWriter
- Defined in:
- lib/locca/android_collection_writer.rb
Instance Method Summary collapse
-
#initialize(file_manager) ⇒ AndroidCollectionWriter
constructor
A new instance of AndroidCollectionWriter.
- #write_to_path(collection, filepath) ⇒ Object
Constructor Details
#initialize(file_manager) ⇒ AndroidCollectionWriter
Returns a new instance of AndroidCollectionWriter.
31 32 33 |
# File 'lib/locca/android_collection_writer.rb', line 31 def initialize(file_manager) @file_manager = file_manager end |
Instance Method Details
#write_to_path(collection, filepath) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/locca/android_collection_writer.rb', line 35 def write_to_path(collection, filepath) if not filepath raise ArgumentException, 'filepath can\'t be nil' end FileUtils.mkdir_p(@file_manager.dirname(filepath)) document = Nokogiri::XML("") document.encoding = "UTF-8" resources = Nokogiri::XML::Node.new('resources', document) collection.sorted_each do |item| if item.comment resources.add_child(Nokogiri::XML::Comment.new(document, " #{item.comment} ")) end if item.plural? node = Nokogiri::XML::Node.new('plurals', document) node["name"] = item.key item.value.each do |key, value| nodeItem = Nokogiri::XML::Node.new('item', document) nodeItem["quantity"] = key nodeItem.content = value node.add_child(nodeItem) end resources.add_child(node) else node = Nokogiri::XML::Node.new('string', document) node["name"] = item.key node.content = item.value resources.add_child(node) end end document.root = resources @file_manager.open(filepath, "w") do |io| io << document.to_xml end end |