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

dimensions[R]
name[RW]
parameters[R]
pattern[R]

Public Class Methods

new(raw_data) click to toggle source

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

chunk?() click to toggle source

Method to check whether a structure is chunk-based.

   # File lib/bones/structure.rb
88 def chunk?
89         return @pattern =~ /chunk/
90 end
element?() click to toggle source

Method to check whether a structure is element-based.

   # File lib/bones/structure.rb
78 def element?
79         return @pattern =~ /element/
80 end
empty?() click to toggle source

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
from_at(n) click to toggle source

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
full?() click to toggle source

Method to check whether a structure is full-based.

    # File lib/bones/structure.rb
 98 def full?
 99         return @pattern =~ /full/
100 end
has_arrayname?() click to toggle source

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
has_parameter?() click to toggle source

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
neighbourhood?() click to toggle source

Method to check whether a structure is neighbourhood-based.

   # File lib/bones/structure.rb
83 def neighbourhood?
84         return @pattern =~ /neighbourhood/
85 end
reverse?() click to toggle source

TODO: Implement the reverse function

   # File lib/bones/structure.rb
30 def reverse?
31         true
32 end
shared?() click to toggle source

Method to check whether a structure is shared-based.

   # File lib/bones/structure.rb
93 def shared?
94         return @pattern =~ /shared/
95 end
to_at(n) click to toggle source

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