Class: NSArray
- Defined in:
- lib/ios/sugarcube-color/nsarray.rb,
lib/osx/sugarcube-color/nsarray.rb,
lib/cocoa/sugarcube-files/nsarray.rb,
lib/cocoa/sugarcube-pointer/nsarray.rb,
lib/cocoa/sugarcube-foundation/nsarray.rb,
lib/cocoa/sugarcube-nsuserdefaults/nsuserdefaults.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cgcolor(alpha = nil) ⇒ Object
-
#nscolor(alpha = 1.0) ⇒ Object
[160, 210, 242].nscolor => 0xA0D2F2.nscolor.
-
#nsindexpath ⇒ NSIndexPath
Creates an NSIndexPath object using the items in ‘self` as the indices.
-
#nsindexset ⇒ NSIndexSet
Creates an NSIndexSet object using the items in ‘self` as the indices.
- #nsorderedset ⇒ Object
- #nsset ⇒ Object
- #skcolor(alpha = nil) ⇒ Object
- #to_nsuserdefaults ⇒ Object
-
#to_pointer(type) ⇒ Pointer
A pointer to the array, of the specified type.
-
#to_pointers(type) ⇒ Pointer
An array of pointers of the specified type.
-
#uicolor(alpha = nil) ⇒ Object
[160, 210, 242].uicolor => 0xA0D2F2.uicolor [160, 210, 242, 0.5].uicolor => 0xA0D2F2.uicolor(0.5).
- #write_to(path_or_url, atomically = true) ⇒ Object
Class Method Details
Instance Method Details
#cgcolor(alpha = nil) ⇒ Object
16 17 18 |
# File 'lib/ios/sugarcube-color/nsarray.rb', line 16 def cgcolor(alpha=nil) uicolor(alpha).CGColor end |
#nscolor(alpha = 1.0) ⇒ Object
[160, 210, 242].nscolor => 0xA0D2F2.nscolor
4 5 6 7 8 9 10 11 12 |
# 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 ⇒ NSIndexPath
Creates an NSIndexPath object using the items in ‘self` as the indices
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 ⇒ NSIndexSet
Creates an NSIndexSet object using the items in ‘self` as the indices
23 24 25 26 27 28 29 30 31 32 33 |
# 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 ⇒ Object
39 40 41 |
# File 'lib/cocoa/sugarcube-foundation/nsarray.rb', line 39 def nsorderedset NSOrderedSet.orderedSetWithArray self end |
#nsset ⇒ Object
35 36 37 |
# File 'lib/cocoa/sugarcube-foundation/nsarray.rb', line 35 def nsset NSSet.setWithArray self end |
#skcolor(alpha = nil) ⇒ Object
20 21 22 |
# File 'lib/ios/sugarcube-color/nsarray.rb', line 20 def skcolor(alpha=nil) uicolor(alpha) end |
#to_nsuserdefaults ⇒ Object
43 44 45 |
# File 'lib/cocoa/sugarcube-nsuserdefaults/nsuserdefaults.rb', line 43 def to_nsuserdefaults self.map { |val| val.to_nsuserdefaults } end |
#to_pointer(type) ⇒ Pointer
Returns A pointer to the array, of the specified type.
5 6 7 8 9 10 11 |
# 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) ⇒ Pointer
Returns An array of pointers of the specified type.
15 16 17 18 19 20 21 |
# 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) ⇒ Object
[160, 210, 242].uicolor => 0xA0D2F2.uicolor [160, 210, 242, 0.5].uicolor => 0xA0D2F2.uicolor(0.5)
5 6 7 8 9 10 11 12 13 14 |
# 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) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# 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 |