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 |
From: FUJIMOTO H. <hi...@im...> - 2003-03-16 00:57:44
|
At Sat, 15 Mar 2003 18:14:25 -0500, Hi, Sam Roberts wrote: > 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: NSObject#to_s (and NSData#to_s) is same as `NSData.description.cString'. The following code snippet may be what you want except it is too verbose. vcdata = OSX::ABAddressBook.sharedAddressBook.me.vCardRepresentation enc = NSProprietaryStringEncoding # specify an appropriate encoding. str = OSX::NSString.alloc.initWithData_encoding( vcdata, enc ) or str = ' ' * vcdata.length vcdata.getBytes(str) str RubyCocoa is implemented like this currently. However, I recognize that behavior of such implementation is not so good. -- FUJIMOTO Hisakuni |
From: Sam R. <sro...@un...> - 2003-03-16 02:07:22
|
Thanks for your very timely help! Where can I find the ruby library files for 'osx/objc/cocoa' and foundation? Are they implemented in C? I want to be able to browse the src to get a better idea what is available, where NSProprietarStringEncoding is defined, etc. I installed the binary image, do I need the source to get these things? Sam Quoteing hi...@im..., on Sun, Mar 16, 2003 at 09:57:54AM +0900: > At Sat, 15 Mar 2003 18:14:25 -0500, > Hi, > > Sam Roberts wrote: > > 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: > > NSObject#to_s (and NSData#to_s) is same as `NSData.description.cString'. > > The following code snippet may be what you want except it is too verbose. > > vcdata = OSX::ABAddressBook.sharedAddressBook.me.vCardRepresentation > enc = NSProprietaryStringEncoding # specify an appropriate encoding. > str = OSX::NSString.alloc.initWithData_encoding( vcdata, enc ) > > or > > str = ' ' * vcdata.length > vcdata.getBytes(str) > str > > RubyCocoa is implemented like this currently. However, I recognize > that behavior of such implementation is not so good. > > -- > FUJIMOTO Hisakuni > > > ------------------------------------------------------- > This SF.net email is sponsored by:Crypto Challenge is now open! > Get cracking and register here for some mind boggling fun and > the chance of winning an Apple iPod: > http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk |
From: FUJIMOTO H. <hi...@im...> - 2003-03-17 05:22:23
|
At Sat, 15 Mar 2003 21:07:11 -0500, Sam Roberts wrote: > Where can I find the ruby library files for 'osx/objc/cocoa' and > foundation? Are they implemented in C? I want to be able to browse the > src to get a better idea what is available, where > NSProprietarStringEncoding is defined, etc. > I installed the binary image, do I need the source to get these things? RubyCocoa implementation is written as mixture of Ruby and Objective-C. Sources of the Ruby part are included in the binary distribution in: /Library/Frameworks/RubyCocoa.framework/Resources/ruby -- hisa |