OptionsProvider

class OptionsProvider

Parent: Object | Class Index
Methods:[], []=, count, each, each_key, each_pair, each_value, has_key?, key?, keys, name, size |
Sample Code:optionsprovidertests.rb |

An OptionsProvider class provides various kinds of options on a Model. You get an OptionsProvider from the OptionsManager. The options are given as name/value pairs.

Instance Methods

[]
The [] method is used to get a value by name or index of the key.
Syntax:
value = optionsprovider[index] value = optionsprovider[name]
Arguments:
index - the index for a specific key name - the name of the specific key
Return Value:
value - the value if successful
Comments:
Example:
model = Sketchup.active_model manager = model.options provider = manager[0] # Retrieves each value for each key option = provider[1]

[]=
The []= method is used to set the value of a specific key.
Syntax:
value = optionsprovider[“key"]=value
Arguments:
“key” – the valid key value – the value to be set
Return Value:
value – the value that was set if successful, or false if unsuccessful.
Comments:
Creates a new attribute for the given key if needed.
Example:
option = provider[1]=10

count
The count method is used to retrieve the size (number of elements) of an options provider.
Syntax:
count = optionsprovider.count
Arguments:
Return Value:
size – the size of the options provider if successful
Comments:
Example:
count = provider.count

each
The each method is used to iterate through all of the attributes.
Syntax:
optionsprovider.each { | key, value | … }
Arguments:
key, value – variables that will hold each key and value as they are found.
Return Value:
Comments:
Throws an exception if there are no keys.
Example:
# Retrieves each key provider.each { |key, value| UI.messagebox key } # Retrieves each corresponding value provider.each { |key, value| UI.messagebox key }

each_key
The each_key method is used to iterate through all of the attribute keys.
Syntax:
optionsprovider.each { | key | … }
Arguments:
key– a variable that will hold each key as they are found.
Return Value:
Comments:
Throws an exception if there are no keys.
Example:
provider.each_key { |key| UI.messagebox key }

each_pair
An alias for each. See OptionsProvider.each
Syntax:
optionsprovider.each_pair {|key, value| ...}
Arguments:
key, value – variables that will hold each key and value as they are found.
Return Value:
Comments:
Throws an exception if there are no keys.
Example:
# Retrieves each key provider.each_pair { |key, value| UI.messagebox key }

each_value
The each_value method is used to iterate through all of the attribute values.
Syntax:
optionsprovider.each_value { | value | … }
Arguments:
value – a variable that will hold each value as they are found.
Return Value:
Comments:
Throws an exception if there are no keys.
Example:
provider.each_value { |value| UI.messagebox value }

has_key?
The has_key? method is used to determine if the options provider has a specific key.
Syntax:
status = provider.has_key? "name"
Arguments:
name - the name of the key you are looking for
Return Value:
status - true if the key exists, false if the key does not exist.
Comments:
Example:

status = provider.has_key? "PageOptions"
if (status)
UI.messagebox status
else
UI.messagebox "Failure"
end

key?
The key? method is used to determine if the options provider has a specific key. This method is the same as has_key? See also OptionsManager.has_key?
Syntax:
status = provider.key? "name"
Arguments:
name - the name of the key you are looking for
Return Value:
status - true if the key exists, false if the key does not exist.
Comments:
Example:

status = provider.has_key? "PageOptions"
if (status)
UI.messagebox status
else
UI.messagebox "Failure"
end

keys
The keys method is used to retrieve an array with all of the attribute keys.
Syntax:
keys = optionsprovider.keys
Arguments:
Return Value:
keys – an array of keys within the options provider if successful
Comments:
Example:

keys = provider.keys
key = keys[0]
if (key)
UI.messagebox key
else
UI.messagebox "Failure"
end

name
The name method is used to retrieve the name of an options provider.
Syntax:
name = optionsprovider.name
Arguments:
Return Value:
name – the name of the options provider if successful
Comments:
Example:
name = provider.name

size
The size method is used to retrieve the size (number of elements) of an options provider. This method is an alias for count. See also OptionsProvider.count.
Syntax:
size = optionsprovider.size
Arguments:
Return Value:
size – the size of the options provider if successful
Comments:
Example:
size = provider.size