Class: NSString
- Inherits:
-
Object
- Object
- NSString
- Defined in:
- lib/sugarcube/document.rb,
lib/sugarcube/nsstring.rb,
lib/sugarcube/notifications.rb
Instance Method Summary collapse
- #document ⇒ Object
- #exists? ⇒ Boolean
-
#localized(value = nil, table = nil) ⇒ Object
(also: #_)
This can be called as ‘“Hello”.localized` or `“Hello”._`.
- #nsurl ⇒ Object
- #post_notification(object = nil, user_info = nil) ⇒ Object
- #uicolor(alpha = nil) ⇒ Object
- #uifont(size = UIFont.systemFontSize) ⇒ Object
- #uiimage ⇒ Object
Instance Method Details
#document ⇒ Object
5 6 7 8 |
# File 'lib/sugarcube/document.rb', line 5 def document @docs ||= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0] @docs.stringByAppendingPathComponent(self) end |
#exists? ⇒ Boolean
10 11 12 |
# File 'lib/sugarcube/document.rb', line 10 def exists? NSFileManager.defaultManager.fileExistsAtPath(self) end |
#localized(value = nil, table = nil) ⇒ Object Also known as: _
This can be called as ‘“Hello”.localized` or `“Hello”._`. The `str._` syntax is meant to be reminiscent of gettext-style `_(str)`.
34 35 36 |
# File 'lib/sugarcube/nsstring.rb', line 34 def localized(value=nil, table=nil) @localized = NSBundle.mainBundle.localizedStringForKey(self, value:value, table:table) end |
#nsurl ⇒ Object
3 4 5 |
# File 'lib/sugarcube/nsstring.rb', line 3 def nsurl @url ||= NSURL.alloc.initWithString(self) end |
#post_notification(object = nil, user_info = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/sugarcube/notifications.rb', line 3 def post_notification(object=nil, user_info=nil) if user_info and not Hash === user_info raise TypeError("Invalid argument #{user_info.class.name} sent to String.post_notification") end if user_info NSNotificationCenter.defaultCenter.postNotificationName(self, object:object, userInfo:user_info) else NSNotificationCenter.defaultCenter.postNotificationName(self, object:object) end end |
#uicolor(alpha = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sugarcube/nsstring.rb', line 15 def uicolor(alpha=nil) if self[0,1] == '#' # #fff if self.length == 4 return (self[1] * 2 + self[2] * 2 + self[3] * 2).to_i(16).uicolor(alpha) end # else return self[1..-1].to_i(16).uicolor(alpha) end begin self.to_sym.uicolor(alpha) rescue SugarNotFoundException self.uiimage.uicolor(alpha) end end |
#uifont(size = UIFont.systemFontSize) ⇒ Object
11 12 13 |
# File 'lib/sugarcube/nsstring.rb', line 11 def uifont(size=UIFont.systemFontSize) @uifont = UIFont.fontWithName(self, size:size) end |
#uiimage ⇒ Object
7 8 9 |
# File 'lib/sugarcube/nsstring.rb', line 7 def uiimage @uiimage = UIImage.imageNamed(self) end |