Class: NSString
- Inherits:
-
Object
- Object
- NSString
- Defined in:
- lib/project/ns_string.rb
Overview
Shamelessly extracted from sugarcube github.com/rubymotion/sugarcube/blob/master/lib/cocoa/sugarcube-files/nsstring.rb
Instance Method Summary collapse
- #document_path ⇒ Object
- #file_exists? ⇒ Boolean
- #remove_file! ⇒ Object
- #resource_exists? ⇒ Boolean
- #resource_path ⇒ Object
Instance Method Details
#document_path ⇒ Object
5 6 7 8 9 10 |
# File 'lib/project/ns_string.rb', line 5 def document_path @@motionconcierge_docs ||= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0] return self if self.hasPrefix(@@motionconcierge_docs) @@motionconcierge_docs.stringByAppendingPathComponent(self) end |
#file_exists? ⇒ Boolean
19 20 21 22 |
# File 'lib/project/ns_string.rb', line 19 def file_exists? path = self.hasPrefix('/') ? self : self.document_path NSFileManager.defaultManager.fileExistsAtPath(path) end |
#remove_file! ⇒ Object
24 25 26 27 28 29 |
# File 'lib/project/ns_string.rb', line 24 def remove_file! ptr = Pointer.new(:id) path = self.hasPrefix('/') ? self : self.document_path NSFileManager.defaultManager.removeItemAtPath(path, error:ptr) ptr[0] end |
#resource_exists? ⇒ Boolean
31 32 33 |
# File 'lib/project/ns_string.rb', line 31 def resource_exists? self.resource_path.file_exists? end |
#resource_path ⇒ Object
12 13 14 15 16 17 |
# File 'lib/project/ns_string.rb', line 12 def resource_path @@motionconcierge_resources ||= NSBundle.mainBundle.resourcePath return self if self.hasPrefix(@@motionconcierge_resources) @@motionconcierge_resources.stringByAppendingPathComponent(self) end |