Class: NSCoder

Inherits:
Object show all
Defined in:
lib/cocoa/sugarcube-nscoder/nscoder.rb,
lib/cocoa/sugarcube-nscoder/nscoder.rb

Overview

Hash-like access for NSCoder. Converts the ‘key` argument to a String, because Symbols can mess things up.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.archive(root, to_file: file) ⇒ Object



85
86
87
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 85

def self.archive(root)
  NSKeyedArchiver.archivedDataWithRootObject(root)
end

.unarchive(data_or_file) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 93

def self.unarchive(data_or_file)
  if data_or_file.is_a?(NSData)
    NSKeyedUnarchiver.unarchiveObjectWithData(data_or_file)
  else
    NSKeyedUnarchiver.unarchiveObjectWithFile(data_or_file)
  end
end

Instance Method Details

#[](key) ⇒ Object



5
6
7
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 5

def [] key
  self.decodeObjectForKey(key.to_s)
end

#[]=(key, value) ⇒ Object



9
10
11
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 9

def []= key, value
  self.encodeObject(value, forKey: key.to_s)
end

#bool(key) ⇒ Object



17
18
19
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 17

def bool(key)
  self.decodeBoolForKey(key.to_s)
end

#double(key) ⇒ Object



21
22
23
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 21

def double(key)
  self.decodeDoubleForKey(key.to_s)
end

#float(key) ⇒ Object



25
26
27
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 25

def float(key)
  self.decodeFloatForKey(key.to_s)
end

#int(key) ⇒ Object



29
30
31
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 29

def int(key)
  self.decodeIntegerForKey(key.to_s)
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 13

def key?(key)
  self.containsValueForKey(key.to_s)
end

#point(key) ⇒ Object



33
34
35
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 33

def point(key)
  CGPointFromString(self.decodeObjectForKey(key.to_s))
end

#rect(key) ⇒ Object



37
38
39
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 37

def rect(key)
  CGRectFromString(self.decodeObjectForKey(key.to_s))
end

#set(key, toSize: value) ⇒ Object



45
46
47
48
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 45

def set(key, toBool: value)
  self.encodeBool(value, forKey: key.to_s)
  self
end

#size(key) ⇒ Object



41
42
43
# File 'lib/cocoa/sugarcube-nscoder/nscoder.rb', line 41

def size(key)
  CGSizeFromString(self.decodeObjectForKey(key.to_s))
end