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:

The Parameter class can be used to maintain a set of meta-informations about types in a given object.

Attributes

description[RW]

The (text) description of the parameter

long_name[RW]

The long name of the parameter, to be translated

name[RW]

The short name of the parameter

reader_symbol[RW]

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.

type[RW]

The actual Commands::CommandType of the parameter

writer_symbol[RW]

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

new(name, writer_symbol, reader_symbol, long_name, type, description) click to toggle source

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

get_string(target) click to toggle source

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
get_value(target) click to toggle source

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
set_from_string(target, str) click to toggle source

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
set_value(target, val) click to toggle source

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