Class: NSString

Inherits:
Object
  • Object
show all
Defined in:
lib/sugarcube/document.rb,
lib/sugarcube/nsstring.rb,
lib/sugarcube/notifications.rb

Instance Method Summary collapse

Instance Method Details

#documentObject



3
4
5
6
# File 'lib/sugarcube/document.rb', line 3

def document
  @docs ||= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
  @docs.stringByAppendingPathComponent(self)
end

#exists?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/sugarcube/document.rb', line 8

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)`.



35
36
37
# File 'lib/sugarcube/nsstring.rb', line 35

def localized(value=nil, table=nil)
  @localized = NSBundle.mainBundle.localizedStringForKey(self, value:value, table:table)
end

#nsurlObject



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, =nil)
  if  and not Hash === 
    raise TypeError("Invalid argument #{.class.name} sent to String.post_notification")
  end

  if 
    NSNotificationCenter.defaultCenter.postNotificationName(self, object:object, userInfo:)
  else
    NSNotificationCenter.defaultCenter.postNotificationName(self, object:object)
  end
end

#uicolor(alpha = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sugarcube/nsstring.rb', line 20

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

  self.uiimage.uicolor(alpha)
end

#uifont(size = UIFont.systemFontSize) ⇒ Object



15
16
17
18
# File 'lib/sugarcube/nsstring.rb', line 15

def uifont(size=UIFont.systemFontSize)
  @uifont ||= {}
  @uifont[size] ||= UIFont.fontWithName(self, size:size)
end

#uiimageObject



7
8
9
# File 'lib/sugarcube/nsstring.rb', line 7

def uiimage
  @uiimage = UIImage.imageNamed(self)
end

#uiimageviewObject



11
12
13
# File 'lib/sugarcube/nsstring.rb', line 11

def uiimageview
  @uiimageview ||= (self.uiimage and self.uiimage.uiimageview or UIImageView.alloc.initWithImage(nil))
end