Class: SciYAG::Backends::Descriptions::Parameter

Inherits:
Object
  • Object
show all
Includes:
Conversion
Defined in:
lib/SciYAG/Backends/descriptions.rb

Overview

A class that describes one parameter that will be fixed at run-time by the user.

Constant Summary

Constants included from Conversion

Conversion::FALSE_RE, Conversion::TRUE_RE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Conversion

#text_to_type

Constructor Details

#initialize(name, writer_symbol, reader_symbol, long_name, type, description) ⇒ Parameter

Returns a new instance of Parameter.



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/SciYAG/Backends/descriptions.rb', line 117

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 = type  
end

Instance Attribute Details

#descriptionObject

The description



104
105
106
# File 'lib/SciYAG/Backends/descriptions.rb', line 104

def description
  @description
end

#long_nameObject

The long name of the parameter, to be translated



96
97
98
# File 'lib/SciYAG/Backends/descriptions.rb', line 96

def long_name
  @long_name
end

#nameObject

The short name of the parameter



93
94
95
# File 'lib/SciYAG/Backends/descriptions.rb', line 93

def name
  @name
end

#reader_symbolObject

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.



101
102
103
# File 'lib/SciYAG/Backends/descriptions.rb', line 101

def reader_symbol
  @reader_symbol
end

#typeObject

The type of the parameter. It can take several values; see Descriptions::Conversion.text_to_type. Moreover, several values for a string parameter can be interpreted by systems in charge of querying the parameter:

  • "File: ..." represents a file, and the rest is the filter, Qt style;

  • "Set" represents a data set, which can queried for by the sets_available function.



115
116
117
# File 'lib/SciYAG/Backends/descriptions.rb', line 115

def type
  @type
end

#writer_symbolObject

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.



101
102
103
# File 'lib/SciYAG/Backends/descriptions.rb', line 101

def writer_symbol
  @writer_symbol
end

Instance Method Details

#get(target) ⇒ Object

Aquires the value from the backend, and returns it



140
141
142
# File 'lib/SciYAG/Backends/descriptions.rb', line 140

def get(target)
  target.send(@reader_symbol).to_s
end

#set(target, value) ⇒ Object

Sets the value of the given parameter in the target. It tries to be clever somehow, using @type to know what should be expected. See the text_to_type function.



134
135
136
137
# File 'lib/SciYAG/Backends/descriptions.rb', line 134

def set(target, value)
  value = text_to_type(value, @type)
  target.send(@writer_symbol, value) 
end

#value(v) ⇒ Object



144
145
146
# File 'lib/SciYAG/Backends/descriptions.rb', line 144

def value(v)
  return text_to_type(v, @type)
end