class Bones::Variablelist

This class is based on the standard Array class. It is meant to contain a list of elements of the Variable class. In that sense, using the Array class will suffice. However, this class extends the list with a small number of addi- tional methods. These methods involve selecting a subset of the list or sorting the list.

Attributes

representative[RW]

Public Instance Methods

inputs() click to toggle source

This method is a short-hand version to select a list of input variables. It calls the select method internally.

   # File lib/bones/variablelist.rb
32 def inputs
33         select(INPUT)
34 end
inputs_only() click to toggle source

This method is a short-hand version to select a list of input only variables. It calls the select method internally.

   # File lib/bones/variablelist.rb
45 def inputs_only
46         self-select(OUTPUT)
47 end
outputs() click to toggle source

This method is a short-hand version to select a list of output variables. It calls the select method internally.

   # File lib/bones/variablelist.rb
38 def outputs
39         select(OUTPUT)
40 end
outputs_only() click to toggle source

This method is a short-hand version to select a list of input only variables. It calls the select method internally.

   # File lib/bones/variablelist.rb
52 def outputs_only
53         self-select(INPUT)
54 end
select(direction) click to toggle source

This method returns a subset of the list, based on the argument direction given. It either returns a list of input variables or a list of output variables.

   # File lib/bones/variablelist.rb
15 def select(direction)
16         array = Variablelist.new()
17         self.each do |element|
18                 array.push(element) if ((direction == INPUT) && (element.input?)) || ((direction == OUTPUT) && (element.output?)) || (element.direction == INOUT)
19         end
20         return array
21 end
set_representative(ids) click to toggle source

Method to set a representative variable for this variable- list. It is set based on the variable’s species-name, e.g. ‘in0’ or ‘out2’.

   # File lib/bones/variablelist.rb
26 def set_representative(ids)
27         @representative = select(ids.to_s.scan(/\D+/).join)[ids.to_s.scan(/\d+/).join.to_i]
28 end
sort_by(alphabet) click to toggle source

This method sorts the list of variables based on its species’ pattern (e.g. element or chunk). An alphabet is based as an argument to this method to specify the prefered order. This alphabet must be an array of strings.

   # File lib/bones/variablelist.rb
60 def sort_by(alphabet)
61         clone = self.clone
62         self.clear
63         alphabet.each do |letter|
64                 clone.each do |array|
65                         self.push(array) if array.species.pattern == letter
66                 end
67         end
68 end