Class: Bones::Structure
Overview
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)
Instance Attribute Summary collapse
-
#dimensions ⇒ Object
readonly
Returns the value of attribute dimensions.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#chunk? ⇒ Boolean
Method to check whether a structure is chunk-based.
-
#element? ⇒ Boolean
Method to check whether a structure is element-based.
-
#empty? ⇒ Boolean
Method to verify if a structure is empty or not (e.g. if it is based on the ‘void’ pattern..
-
#from_at(n) ⇒ Object
Method to get the start of a range given a dimension ‘n’.
-
#full? ⇒ Boolean
Method to check whether a structure is full-based.
-
#has_arrayname? ⇒ Boolean
Method to find out if the structure has a arrayname defined.
-
#has_parameter? ⇒ Boolean
Method to find out if the structure has a parameter.
-
#initialize(raw_data) ⇒ Structure
constructor
The structure is initialized by the full name given as a string.
-
#neighbourhood? ⇒ Boolean
Method to check whether a structure is neighbourhood-based.
-
#reverse? ⇒ Boolean
TODO: Implement the reverse function.
-
#shared? ⇒ Boolean
Method to check whether a structure is shared-based.
-
#to_at(n) ⇒ Object
Method to get the end of a range given a dimension ‘n’.
Methods inherited from Common
#flatten_hash, #from, #replace_defines, #search_and_replace, #search_and_replace!, #sum, #sum_and_from, #to
Constructor Details
#initialize(raw_data) ⇒ Structure
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.
19 20 21 22 23 24 25 26 27 |
# File 'lib/bones/structure.rb', line 19 def initialize(raw_data) data = raw_data.split(PIPE) pattern_data = data[1].split('(') dimension_data = data[0].split('[') @pattern = pattern_data[0].strip @name = (dimension_data.length == 2) ? dimension_data[0].strip : '' @dimensions = (dimension_data.length == 2) ? dimension_data[1].delete(']').split(DIM_SEP) : dimension_data[0].split(DIM_SEP) @parameters = (pattern_data.length > 1) ? pattern_data[1].delete(')').split(DIM_SEP) : [] end |
Instance Attribute Details
#dimensions ⇒ Object (readonly)
Returns the value of attribute dimensions.
13 14 15 |
# File 'lib/bones/structure.rb', line 13 def dimensions @dimensions end |
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/bones/structure.rb', line 14 def name @name end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
13 14 15 |
# File 'lib/bones/structure.rb', line 13 def parameters @parameters end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
13 14 15 |
# File 'lib/bones/structure.rb', line 13 def pattern @pattern end |
Instance Method Details
#chunk? ⇒ Boolean
Method to check whether a structure is chunk-based.
88 89 90 |
# File 'lib/bones/structure.rb', line 88 def chunk? return @pattern =~ /chunk/ end |
#element? ⇒ Boolean
Method to check whether a structure is element-based.
78 79 80 |
# File 'lib/bones/structure.rb', line 78 def element? return @pattern =~ /element/ end |
#empty? ⇒ Boolean
Method to verify if a structure is empty or not (e.g. if it is based on the ‘void’ pattern.
73 74 75 |
# File 'lib/bones/structure.rb', line 73 def empty? return @pattern =~ /void/ end |
#from_at(n) ⇒ Object
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.
50 51 52 53 54 55 56 |
# File 'lib/bones/structure.rb', line 50 def from_at(n) if (neighbourhood?) return simplify('('+from(@dimensions[n])+')-('+from(@parameters[n])+')') else return simplify(from(@dimensions[n])) end end |
#full? ⇒ Boolean
Method to check whether a structure is full-based.
98 99 100 |
# File 'lib/bones/structure.rb', line 98 def full? return @pattern =~ /full/ end |
#has_arrayname? ⇒ Boolean
Method to find out if the structure has a arrayname defined. This is optional for a structure.
43 44 45 |
# File 'lib/bones/structure.rb', line 43 def has_arrayname? return (@name != '') end |
#has_parameter? ⇒ Boolean
Method to find out if the structure has a parameter. This is only the case if it is neighbourhood or chunk based.
37 38 39 |
# File 'lib/bones/structure.rb', line 37 def has_parameter? return (@parameters != []) end |
#neighbourhood? ⇒ Boolean
Method to check whether a structure is neighbourhood-based.
83 84 85 |
# File 'lib/bones/structure.rb', line 83 def neighbourhood? return @pattern =~ /neighbourhood/ end |
#reverse? ⇒ Boolean
TODO: Implement the reverse function
30 31 32 |
# File 'lib/bones/structure.rb', line 30 def reverse? true end |
#shared? ⇒ Boolean
Method to check whether a structure is shared-based.
93 94 95 |
# File 'lib/bones/structure.rb', line 93 def shared? return @pattern =~ /shared/ end |
#to_at(n) ⇒ Object
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.
61 62 63 64 65 66 67 68 69 |
# File 'lib/bones/structure.rb', line 61 def to_at(n) if (chunk?) return simplify('((('+to(@dimensions[n])+'+1)/('+to(@parameters[n])+'+1))-1)') elsif (neighbourhood?) return simplify('('+to(@dimensions[n])+')-('+to(@parameters[n])+')') else return simplify(to(@dimensions[n])) end end |