| Class | RS::Utils::RSProperties |
| In: |
rsil/utils/rsproperties.rb
|
| Parent: | RS::Utils::RSObjcWrapper |
| Class: | RSProperties |
| File: | rsproperties.rb |
| Purpose: | RSProperties is used to keep paremters as key-value pairs. |
| Created by: | Mario Pehle, 2006/04/29 |
| Required modules: | - |
| Offers functions: | - |
| DEFAULT_CAPACITY | = | 13 | The default value for capacity of the basic properties object. |
| Description: | Creates a RSProperties object through wrapping of OSX::NSDictionary. You can specify a start capacity. The capacity will be increased when not large enough. |
| Precondition: | capacity > 0 |
| Postcondition: | An OSX::NSMutableDictionary is initialized. |
| Exceptions: | ArgumentError |
| Uses: | - |
| Returns: | self |
| Parameters: | Name | i/o/io | default | Meaning |
| : | capacity | i | DEFAULT_CAPACITY | The start capacity |
# File rsil/utils/rsproperties.rb, line 48
48: def initialize capacity=DEFAULT_CAPACITY
49: (c = Integer capacity) rescue raise ArgumentError, "Can not convert argument 'capacity'."
50: raise ArgumentError, "Argument 'capacity' has to be a positive Fixnum." if c <= 0
51: @nsdictionary = OSX::NSMutableDictionary.dictionaryWithCapacity c
52: assert "@nsdictionary not initialized" if @nsdictionary.nil?
53: self
54: end
| Description: | Removes all items. Unfortunately there is no return value of the basic method, so it is not clear, that the method acted correctly. |
| Precondition: | - |
| Postcondition: | The NSMutableDictionary is empty. |
| Exceptions: | ArgumentError |
| Uses: | OSX::NSMutableDictionary#removeAllObjects |
| Returns: | self |
| Parameters: | Name | i/o/io | default | Meaning |
# File rsil/utils/rsproperties.rb, line 68
68: def clear
69: @nsdictionary.removeAllObjects
70: self
71: end
| Description: | Removes all key-value pairs and adds key-value pairs from given RSProperties. Unfortunately there is no return value of the basic method, so it is not clear, that the method acted correctly. |
| Precondition: | - |
| Postcondition: | NSDictionary only with key-value pairs of given object. |
| Exceptions: | ArgumentError |
| Uses: | RSProperties#objc_object, NSMutableDictionary.removeObjectForKey |
| Returns: | self |
| Parameters: | Name | i/o/io | default | Meaning |
| : | rsproperties | i | - | RSProperties |
# File rsil/utils/rsproperties.rb, line 104
104: def from_rsproperties rsproperties
105: if rsproperties.kind_of? self.class
106: @nsdictionary.setDictionary rsproperties.objc_object
107: assert "@nsdictionary not reinitialized" if @nsdictionary.nil?
108: else
109: raise ArgumentError, "No valid argument."
110: end
111: self
112: end
| Description: | Determines the value for a given key. |
| Precondition: | - |
| Postcondition: | The type of return value is not clear because of th value for the key on one and the convertion of RubyCocoa (OSX) on the other hand. |
| Exceptions: | StandardError |
| Uses: | OSX::NSMutableDictionary#objectForKey |
| Returns: | Object if valid key, else nil |
| Parameters: | Name | i/o/io | default | Meaning |
| : | key | i | - | Object |
# File rsil/utils/rsproperties.rb, line 127
127: def get key
128: begin
129: value = @nsdictionary.objectForKey(key)
130: case value.oc_class.to_s
131: when 'NSCFString'
132: value = value.to_s
133: when 'NSDecimalNumber'
134: value = value.to_f
135: end
136: return value
137: rescue
138: raise StandardError, "Can not determine value for key '#{key}'."
139: end
140: nil
141: end
| Description: | Gives access to the basic object of this object, a OSX::NSMutableDictionary. |
| Precondition: | - |
| Postcondition: | - |
| Exceptions: | - |
| Uses: | - |
| Returns: | OSX::NSMutableDictionary / OSX::OCObject |
| Parameters: | Name | i/o/io | default | Meaning |
# File rsil/utils/rsproperties.rb, line 174
174: def objc_object
175: @nsdictionary
176: end
| Description: | Removes the key-value pairs with the given key(s). Unfortunately there is no return value of the basic method, so it is not clear, that the method acted correctly. |
| Precondition: | - |
| Postcondition: | The NSDictionray does not hold key-value pairs of given keys any longer. |
| Exceptions: | ArgumentError |
| Uses: | OSX::NSMutableDictionary#removeObjectForKey |
| Returns: | self |
| Parameters: | Name | i/o/io | default | Meaning |
| : | keys | i | - | Object / Array |
# File rsil/utils/rsproperties.rb, line 86
86: def remove keys
87: @nsdictionary.removeObjectForKey keys
88: self
89: end
| Description: | Adds / sets a key-value pair. |
| Precondition: | - |
| Postcondition: | Changed NSDictionary. When the key already exists, its value is set to ‘object’. |
| Exceptions: | - |
| Uses: | OSX::NSMutableDictionary.setOjbect:forKey |
| Returns: | self |
| Parameters: | Name | i/o/io | default | Meaning |
| : | key | i | - | Object |
| : | object | i | - | Object |
# File rsil/utils/rsproperties.rb, line 157
157: def set key, object
158: value = @nsdictionary.setObject object, :forKey, key
159: self
160: end