Class: CTioga2::Data::Backends::Parameter
- Inherits:
-
Object
- Object
- CTioga2::Data::Backends::Parameter
- Defined in:
- lib/ctioga2/data/backends/parameter.rb
Overview
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 from String and for user interaction in general;
-
some explanative text, used to inform the user: #long_name and #description
-
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.
Instance Attribute Summary collapse
-
#description ⇒ Object
The (text) description of the parameter.
-
#long_name ⇒ Object
The long name of the parameter, to be translated.
-
#name ⇒ Object
The short name of the parameter.
-
#reader_symbol ⇒ Object
The function names that should be used to set the symbol and retrieve it’s current value.
-
#type ⇒ Object
The actual Commands::CommandType of the parameter.
-
#writer_symbol ⇒ Object
The function names that should be used to set the symbol and retrieve it’s current value.
Instance Method Summary collapse
-
#get_string(target) ⇒ Object
Aquires the value from the backend, and returns it in the form of a string.
-
#get_value(target) ⇒ Object
Aquires the value from the backend, and returns it.
-
#initialize(name, writer_symbol, reader_symbol, long_name, type, description) ⇒ Parameter
constructor
Creates a new Parameter with the given symbols.
-
#set_from_string(target, str) ⇒ Object
Uses the #writer_symbol of the target to set the value of the parameter to the one converted from the String str.
-
#set_value(target, val) ⇒ Object
Sets directly the target parameter, without type conversion.
Constructor Details
#initialize(name, writer_symbol, reader_symbol, long_name, type, description) ⇒ Parameter
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.
68 69 70 71 72 73 74 75 76 77 78 |
# 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 |
Instance Attribute Details
#description ⇒ Object
The (text) description of the parameter
59 60 61 |
# File 'lib/ctioga2/data/backends/parameter.rb', line 59 def description @description end |
#long_name ⇒ Object
The long name of the parameter, to be translated
51 52 53 |
# File 'lib/ctioga2/data/backends/parameter.rb', line 51 def long_name @long_name end |
#name ⇒ Object
The short name of the parameter
48 49 50 |
# File 'lib/ctioga2/data/backends/parameter.rb', line 48 def name @name end |
#reader_symbol ⇒ Object
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.
56 57 58 |
# File 'lib/ctioga2/data/backends/parameter.rb', line 56 def reader_symbol @reader_symbol end |
#type ⇒ Object
The actual Commands::CommandType of the parameter
62 63 64 |
# File 'lib/ctioga2/data/backends/parameter.rb', line 62 def type @type end |
#writer_symbol ⇒ Object
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.
56 57 58 |
# File 'lib/ctioga2/data/backends/parameter.rb', line 56 def writer_symbol @writer_symbol end |
Instance Method Details
#get_string(target) ⇒ Object
Aquires the value from the backend, and returns it in the form of a string
95 96 97 |
# File 'lib/ctioga2/data/backends/parameter.rb', line 95 def get_string(target) return type_to_string(get_value(target)) end |
#get_value(target) ⇒ Object
Aquires the value from the backend, and returns it.
100 101 102 |
# File 'lib/ctioga2/data/backends/parameter.rb', line 100 def get_value(target) target.send(@reader_symbol) end |
#set_from_string(target, str) ⇒ Object
Uses the #writer_symbol of the target to set the value of the parameter to the one converted from the String str
88 89 90 |
# File 'lib/ctioga2/data/backends/parameter.rb', line 88 def set_from_string(target, str) set_value(target, string_to_type(str)) end |
#set_value(target, val) ⇒ Object
Sets directly the target parameter, without type conversion
82 83 84 |
# File 'lib/ctioga2/data/backends/parameter.rb', line 82 def set_value(target, val) target.send(@writer_symbol, val) end |