Class: NSString
Overview
HotCocoa extensions for the NSString class.
Instance Method Summary collapse
-
#camel_case ⇒ Object
Borrowed from Active Support.
-
#underscore ⇒ Object
Borrowed from Active Support.
-
#with_attributes(attributes = {}) ⇒ NSMutableAttributedString
Create an attributed string with the given attributes.
Instance Method Details
#camel_case ⇒ Object
Borrowed from Active Support.
18 19 20 |
# File 'lib/hotcocoa/core_extensions/nsstring.rb', line 18 def camel_case gsub /(?:^|_)(.)/ do $1.upcase end end |
#underscore ⇒ Object
Borrowed from Active Support.
7 8 9 10 11 12 13 14 |
# File 'lib/hotcocoa/core_extensions/nsstring.rb', line 7 def underscore new_string = gsub /::/, '/' new_string.gsub! /([A-Z]+)([A-Z][a-z])/, '\1_\2' new_string.gsub! /([a-z\d])([A-Z])/, '\1_\2' new_string.tr! '-', '_' new_string.downcase! new_string end |
#with_attributes(attributes = {}) ⇒ NSMutableAttributedString
Create an attributed string with the given attributes. The list of applicable attributes can be found in the Apple documentation for NSAttributedString class, as well as the ATTRIBUTE_KEYS hash in the HotCocoa::NSRangedProxyAttributeHash class.
30 31 32 33 34 |
# File 'lib/hotcocoa/core_extensions/nsstring.rb', line 30 def with_attributes attributes = {} attributed_string = NSMutableAttributedString.alloc.initWithString self attributed_string.attributes << attributes attributed_string end |