Here is a swatch of code that creates the second degree subject complement matrix point array.
query1att is a variable which holds the list of subject complements for each of the first degree subject complements. This then iterates with a nested loop if there are any subject complements found in the fia array for any of the first degree subject complements.
Please be aware that if you see a "##" it is in place of a double lessthan. The lessthans play havoc on the html tags
fia = fiaconstant #renew the list of fia entries
fpa = fpaconstant #renew the list of fpa entries
thisatt = Array.new #this makes a new array to hold the position info for the current attribute
thisatt##fpa.assoc(x) #this takes the current attribute (x) and searches for it in the position array returning the four part array [name, x, y, listposition]
thisatt = thisatt[0] #this changes this object from a compound array to an array
puts thisatt
sda = Array.new #this makes a new array to hold the posible list of attributes derived from searching the fia array with the current attribute
next if fia.assoc(x) == nil
sda##fia.assoc(x) #this does that search and retrieval
sda = sda[0] #this changes this object from a compound array to an array. important!!
puts "this is x", x
#next if sda[0] == nil #this goes to the next query1att array attribute if there is no entry in fia for the attribute
#next if sda == nil #this goes to the next query1att array attribute if there is no entry in fia for the attribute
sda.each do |att| #this each loop will take the list of possible attributes and itterate through them, this is a nested itterator within the above loop
puts "this is in the sub each loop the current att are", att, thisatt[0].to_s
fpa = fpaconstant #refresh the fpa array
sdaxy = Array.new #a new array to temporaraly hold the current 2nd degree attributes position info
sdaxy##fpa.assoc(att) #this puts that info into that array
sdaxy = sdaxy[0] #these next four statements make vars out of x and y position info from the two itterative arrays so that they can be put into the qt12degatt array for later use in outputting lineto statements in the postscript
next if sdaxy == nil
onex = thisatt[1]
oney = thisatt[2]
twox = sdaxy[1]
twoy = sdaxy[2]
puts onex.to_s, oney.to_s, twox.to_s, twoy.to_s
qt12degatt##[onex.to_s, oney.to_s, twox.to_s, twoy.to_s] #this is the array of xy positions being put into the main output array
end
end
Arrays in Ruby can hold arrays themselves, and this can be useful when you need to have a complex set of indexed data, each position in the super-array holds a sub-array. I have found using these nested arrays is a simple way of creating modular information sets that I can structure data within and in this case run some outputting code on to then write my moveto, lineto statements into the .ps file.
No comments:
Post a Comment