class Bones::Structure
This class represents a single structure in a species. Such a structure is a single input or output ‘structure’. Stuctures can be set as part of array variables. Examples of structures are given below:
0:9|element 0:0|shared 0:31,0:31|neighbourhood(-1:1,-1:1) 0:99,0:9|chunk(0:0,0:9)
Attributes
Public Class Methods
The structure is initialized by the full name given as a string. It is then analyzed and stored accordingly in a number of class variables.
# File lib/bones/structure.rb 19 def initialize(raw_data) 20 data = raw_data.split(PIPE) 21 pattern_data = data[1].split('(') 22 dimension_data = data[0].split('[') 23 @pattern = pattern_data[0].strip 24 @name = (dimension_data.length == 2) ? dimension_data[0].strip : '' 25 @dimensions = (dimension_data.length == 2) ? dimension_data[1].delete(']').split(DIM_SEP) : dimension_data[0].split(DIM_SEP) 26 @parameters = (pattern_data.length > 1) ? pattern_data[1].delete(')').split(DIM_SEP) : [] 27 end
Public Instance Methods
Method to check whether a structure is chunk-based.
# File lib/bones/structure.rb 88 def chunk? 89 return @pattern =~ /chunk/ 90 end
Method to check whether a structure is element-based.
# File lib/bones/structure.rb 78 def element? 79 return @pattern =~ /element/ 80 end
Method to verify if a structure is empty or not (e.g. if it is based on the ‘void’ pattern.
# File lib/bones/structure.rb 73 def empty? 74 return @pattern =~ /void/ 75 end
Method to get the start of a range given a dimension ‘n’. The method returns the proper simplified result, taking chunk/neighbourhood-sizes into account.
# File lib/bones/structure.rb 50 def from_at(n) 51 if (neighbourhood?) 52 return simplify('('+from(@dimensions[n])+')-('+from(@parameters[n])+')') 53 else 54 return simplify(from(@dimensions[n])) 55 end 56 end
Method to check whether a structure is full-based.
# File lib/bones/structure.rb 98 def full? 99 return @pattern =~ /full/ 100 end
Method to find out if the structure has a arrayname defined. This is optional for a structure.
# File lib/bones/structure.rb 43 def has_arrayname? 44 return (@name != '') 45 end
Method to find out if the structure has a parameter. This is only the case if it is neighbourhood or chunk based.
# File lib/bones/structure.rb 37 def has_parameter? 38 return (@parameters != []) 39 end
Method to check whether a structure is neighbourhood-based.
# File lib/bones/structure.rb 83 def neighbourhood? 84 return @pattern =~ /neighbourhood/ 85 end
TODO: Implement the reverse function
# File lib/bones/structure.rb 30 def reverse? 31 true 32 end
Method to get the end of a range given a dimension ‘n’. The method returns the proper simplified result, taking chunk/neighbourhood-sizes into account.
# File lib/bones/structure.rb 61 def to_at(n) 62 if (chunk?) 63 return simplify('((('+to(@dimensions[n])+'+1)/('+to(@parameters[n])+'+1))-1)') 64 elsif (neighbourhood?) 65 return simplify('('+to(@dimensions[n])+')-('+to(@parameters[n])+')') 66 else 67 return simplify(to(@dimensions[n])) 68 end 69 end