Skip to content

Instantly share code, notes, and snippets.

@ravicious
Created December 22, 2008 10:27
Show Gist options
  • Save ravicious/38950 to your computer and use it in GitHub Desktop.
Save ravicious/38950 to your computer and use it in GitHub Desktop.
require 'rexml/document'
xml = REXML::Document.new(File.open("list.xml"))
gg_numbers = Array.new
gg_nicknames = Array.new
gg_list = Array.new
file = "list.txt"
# dodaję do tablicy kolejne JID-y
xml.elements.each("//item") { |element| gg_numbers.push(element.attributes["jid"]) }
# usuwam z każdego JID-u "@gg.jabber.wp.pl", pozostawiając same numery GG
gg_numbers.collect! { |x| x.gsub(/@gg.jabber.wp.pl/, '') }
# dodaję do tablicy kolejne nicki
xml.elements.each("*/item/nickname") { |element| gg_nicknames.push(element.text) }
gg_nicknames_formated = gg_nicknames.collect! {|x| ';;' + x + ';' + x + ';;;'}
gg_numbers_formated = gg_numbers.collect! {|x| x + ';;0;;0;;0;' + "\n"}
gg_list = [gg_nicknames_formated, gg_numbers_formated]
gg_list = gg_list.transpose
File.open(file, 'w+') { |f| gg_list.each {|i| f << i}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment