From: Sam R. <sro...@un...> - 2003-03-15 23:14:42
|
Hi, just started working with ruby cocoa, and am having a lot of fun. Why does OSX::NSData.to_s return a ruby String that looks like "<xxxxxx xxxxxx>" (where x are hex digits)? I didn't expect this: [ensemble] ~/p/ruby/vcard $ ruby -r osx/addressbook -e "p OSX::ABAddressBook.sharedAddressBook.me.vCardRepresentation.to_s" "<42454749 4e3a5643 4152440d 0a564552 53494f4e 3a332e30 0d0a4e3a 526f6265 7274733b 53616d3b 3b3b0d0a 464e3a53 616d2052 6f626572 74730d0a 454d4149 4c3b7479 70653d48 4f4d453b 74797065 3d707265 663a7372 6f626572 74734075 6e697365 7276652e 636f6d0d 0a54454c 3b747970 653d574f 524b3b74 7970653d 70726566 3a393035 2d353031 2d333738 310d0a54 454c3b74 7970653d 4641583a 3930352d 3930372d 34323330 0d0a5445 4c3b7479 70653d48 4f4d453a 34313620 35333520 35333430 0d0a4144 523b7479 70653d48 4f4d453b 74797065 3d707265 663a3b3b 32373620 57657374 6d6f7265 6c616e64 20417665 2e3b546f 726f6e74 6f3b4f4e 3b4d3648 20334135 3b43616e 6164610d 0a4e4f54 453a4341 5445474f 52494553 3a20416d 69732f46 616d696c 6c650d0a 42444159 3b76616c 75653d64 6174653a 31393730 2d30372d 31340d0a 454e443a 56434152 440d0a>" Currently I am doing: nsdata.to_s.scan(/[0-9a-f]{2}/) .collect {|o| o.hex.chr}.join (is there an easier way to do hex->binary conversions in Ruby? that was surprisingly hard, I expected to be able to use String.unpack, but couldn't see how) to convert the hex to a vCard: BEGIN:VCARD ... etc.... I also see: [ensemble] ~/p/ruby/vcard $ ruby -r osx/addressbook -e "p OSX::ABAddressBook.sharedAddressBook.me.vCardRepresentation.bytes" #<OSX::ObjcPtr:0x1bdf40 cptr=0x3d0990 allocated_size=0> and I thought maybe I could get a byte string out of that: [ensemble] ~/p/ruby/vcard $ ruby -r osx/addressbook -e "p OSX::ABAddressBook.sharedAddressBook.me.vCardRepresentation.bytes.bytestr" -e:1:in `bytestr': wrong argument type nil (expected Fixnum) (TypeError) from -e:1 [ensemble] ~/p/ruby/vcard $ ruby -r osx/addressbook -e "p OSX::ABAddressBook.sharedAddressBook.me.vCardRepresentation.bytes.bytestr(0)" "" [ensemble] ~/p/ruby/vcard $ ruby -r osx/addressbook -e "p OSX::ABAddressBook.sharedAddressBook.me.vCardRepresentation.length" 347 I feel I'm getting closer... Could anybody point me the way? Thanks, Sam |