Sha256: 4f449978cae027b9bb3945da58da874a041b8b85a2d5b3bfd181b493b61351e4

Contents?: true

Size: 818 Bytes

Versions: 4

Compression:

Stored size: 818 Bytes

Contents

class String

  def uiimage
    UIImage.imageNamed(self)
  end

  def uifont(size=UIFont.systemFontSize)
    UIFont.fontWithName(self, size:size)
  end

  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

  # This can be called as `"Hello".localized` or `"Hello"._`.  The `str._`
  # syntax is meant to be reminiscent of gettext-style `_(str)`.
  def localized(value=nil, table=nil)
    NSBundle.mainBundle.localizedStringForKey(self, value:value, table:table)
  end
  alias :_ :localized

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sugarcube-0.1.4 lib/sugarcube/string.rb
sugarcube-0.1.3 lib/sugarcube/string.rb
sugarcube-0.1.2 lib/sugarcube/string.rb
sugarcube-0.1.1 lib/sugarcube/string.rb