class NSArray
Public Class Methods
read_from(path_or_url)
click to toggle source
# File lib/cocoa/sugarcube-files/nsarray.rb, line 5 def read_from(path_or_url) case path_or_url when NSURL self.arrayWithContentsOfURL(path_or_url) when NSString self.arrayWithContentsOfFile(path_or_url) else false end end
Public Instance Methods
cgcolor(alpha=nil)
click to toggle source
# File lib/ios/sugarcube-color/nsarray.rb, line 16 def cgcolor(alpha=nil) uicolor(alpha).CGColor end
nscolor(alpha=1.0)
click to toggle source
[160, 210, 242].nscolor => 0xA0D2F2.nscolor
# File lib/osx/sugarcube-color/nsarray.rb, line 4 def nscolor(alpha=1.0) red = self[0] / 255.0 green = self[1] / 255.0 blue = self[2] / 255.0 if self[3] alpha = self[3] end NSColor.rgba(red, green, blue, alpha.to_f) end
nsindexpath()
click to toggle source
Creates an NSIndexPath
object using the items in `self` as the indices @return [NSIndexPath]
# File lib/cocoa/sugarcube-foundation/nsarray.rb, line 5 def nsindexpath if self.length == 0 raise "An index path must have at least one index" end path = nil self.each do |val| if path path = path.indexPathByAddingIndex(val) else path = NSIndexPath.indexPathWithIndex(val) end end return path end
nsindexset()
click to toggle source
Creates an NSIndexSet
object using the items in `self` as the indices @return [NSIndexSet]
# File lib/cocoa/sugarcube-foundation/nsarray.rb, line 23 def nsindexset if self.length == 0 raise "An index set must have at least one index" end set = NSMutableIndexSet.indexSet self.each do |val| set.addIndex val end set end
nsorderedset()
click to toggle source
# File lib/cocoa/sugarcube-foundation/nsarray.rb, line 39 def nsorderedset NSOrderedSet.orderedSetWithArray self end
nsset()
click to toggle source
# File lib/cocoa/sugarcube-foundation/nsarray.rb, line 35 def nsset NSSet.setWithArray self end
skcolor(alpha=nil)
click to toggle source
# File lib/ios/sugarcube-color/nsarray.rb, line 20 def skcolor(alpha=nil) uicolor(alpha) end
to_nsuserdefaults()
click to toggle source
# File lib/cocoa/sugarcube-nsuserdefaults/nsuserdefaults.rb, line 43 def to_nsuserdefaults self.map { |val| val.to_nsuserdefaults } end
to_object()
click to toggle source
# File lib/cocoa/sugarcube-anonymous/anonymous_array.rb, line 42 def to_object SugarCube::AnonymousArray.new(self) end
to_pointer(type)
click to toggle source
@param type [Symbol] type A pointer type from the list at {www.rubymotion.com/developer-center/guides/runtime/ RubyMotion Pointers Reference#_pointers} @return [Pointer] A pointer to the array, of the specified type
# File lib/cocoa/sugarcube-pointer/nsarray.rb, line 5 def to_pointer(type) ret = Pointer.new(type, self.length) self.each_index do |i| ret[i] = self[i] end ret end
to_pointers(type)
click to toggle source
@param type [Symbol] type A pointer type from the list at {www.rubymotion.com/developer-center/guides/runtime/ RubyMotion Pointers Reference#_pointers} @return [Pointer] An array of pointers of the specified type
# File lib/cocoa/sugarcube-pointer/nsarray.rb, line 15 def to_pointers(type) self.map do |val| ptr = Pointer.new(type) ptr[0] = val ptr end end
uicolor(alpha=nil)
click to toggle source
[160, 210, 242].uicolor => 0xA0D2F2.uicolor [160, 210, 242, 0.5].uicolor => 0xA0D2F2.uicolor(0.5)
# File lib/ios/sugarcube-color/nsarray.rb, line 5 def uicolor(alpha=nil) red = self[0] / 255.0 green = self[1] / 255.0 blue = self[2] / 255.0 if self[3] alpha = self[3] end alpha ||= 1.0 UIColor.colorWithRed(red, green: green, blue: blue, alpha: alpha.to_f) end
write_to(path_or_url, atomically=true)
click to toggle source
# File lib/cocoa/sugarcube-files/nsarray.rb, line 18 def write_to(path_or_url, atomically=true) case path_or_url when NSURL self.writeToURL(path_or_url, atomically: atomically) when NSString self.writeToFile(path_or_url, atomically: atomically) else false end end