class CTioga2::Data::Backends::Parameter
A parameter describes a way of storing some information into an instance of an object. No type checking is done on the target object when the actual reading/writing is done. However, the type checking is done upstream by the Description system.
A Parameter
consists of several things:
-
a
name
, to identify it in a unique fashion; -
a
type
, used to convert to and fromString
and for user interaction in general; -
some explanative text, used to inform the user:
long_name
anddescription
-
two symbols that are used to gain read and write access of the parameter on the target object.
The Parameter
class can be used to maintain a set of meta-informations about types in a given object.
Attributes
The (text) description of the parameter
The long name of the parameter, to be translated
The short name of the parameter
The function names that should be used to set the symbol and retrieve it's current value. The corresponding functions should read or return a string, and writer(reader) should be a noop.
The actual Commands::CommandType
of the parameter
The function names that should be used to set the symbol and retrieve it's current value. The corresponding functions should read or return a string, and writer(reader) should be a noop.
Public Class Methods
Creates a new Parameter
with the given symbols. Remember that if you don't intend to use get, get_raw, set and set_raw, you don't need to pass meaningful values to writer_symbol and reader_symbol.
# File lib/ctioga2/data/backends/parameter.rb, line 68 def initialize(name, writer_symbol, reader_symbol, long_name, type, description) @name = name @writer_symbol = writer_symbol @reader_symbol = reader_symbol @description = description @long_name = long_name @type = Commands::CommandType::get_type(type) end
Public Instance Methods
Aquires the value from the backend, and returns it in the form of a string
# File lib/ctioga2/data/backends/parameter.rb, line 95 def get_string(target) return type_to_string(get_value(target)) end
Aquires the value from the backend, and returns it.
# File lib/ctioga2/data/backends/parameter.rb, line 100 def get_value(target) target.send(@reader_symbol) end
Uses the writer_symbol
of the target to set the value of the parameter to the one converted from the String
str
# File lib/ctioga2/data/backends/parameter.rb, line 88 def set_from_string(target, str) set_value(target, string_to_type(str)) end
Sets directly the target parameter, without type conversion
# File lib/ctioga2/data/backends/parameter.rb, line 82 def set_value(target, val) target.send(@writer_symbol, val) end