class NSData
Public Class Methods
from_base64(base64_data)
click to toggle source
factory method to convert a base64 string into NSData
.
# File lib/cocoa/sugarcube-base64/nsdata.rb, line 12 def self.from_base64(base64_data) NSData.alloc.initWithBase64EncodedData(base64_data, options: 0) end
read_from(path_or_url)
click to toggle source
# File lib/cocoa/sugarcube-files/nsdata.rb, line 5 def read_from(path_or_url) case path_or_url when NSURL self.dataWithContentsOfURL(path_or_url) when NSString self.dataWithContentsOfFile(path_or_url) else false end end
Public Instance Methods
nsimage()
click to toggle source
@return [NSImage]
# File lib/osx/sugarcube-nsdata/nsdata.rb, line 4 def nsimage return NSImage.alloc.initWithData(self) end
nsstring(encoding=NSUTF8StringEncoding)
click to toggle source
to_base64()
click to toggle source
converts an NSData
instance into a base64 string. @todo Support NSDataBase64EncodingOptions options - easy to add, but I want to add specs, too, and a hash format (e.g. line_length: 64 => NSDataBase64Encoding64CharacterLineLength).
# File lib/cocoa/sugarcube-base64/nsdata.rb, line 7 def to_base64 self.base64EncodedStringWithOptions(0) end
uiimage(scale=nil)
click to toggle source
@return [UIImage]
# File lib/ios/sugarcube-nsdata/nsdata.rb, line 4 def uiimage(scale=nil) if scale return UIImage.imageWithData(self, scale:scale) else return UIImage.imageWithData(self) end end
write_to(path_or_url, atomically=true)
click to toggle source
# File lib/cocoa/sugarcube-files/nsdata.rb, line 18 def write_to(path_or_url, atomically=true) case path_or_url when NSURL self.writeToURL(path_or_url, atomically: atomically) when NSString self.writeToFile(path_or_url, atomically: atomically) else false end end