-
Notifications
You must be signed in to change notification settings - Fork 0
/
old code
36 lines (36 loc) · 1.64 KB
/
old code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
From the bottles contoller
def create_array_from_hash (p_hash, p_array, p_level, p_average, p_createLink, p_searchParams, p_parentTarget=nil)
# p_hash is the recursive hash developed below
# p_array is the new array. each row will be a display. children will be hidden
# p_average is a flag indicating whether to average... if not, then it defaults to sum
# p_createLink is a flag indicating whether or not to generate the info needed for an html link
# p_searchParams is an array used for generating the html link. it provides the search key and the "display_value" is the search value
if p_createLink
v_searchParam = p_searchParams[p_level]
else
v_searchParam = nil
end
p_hash.each{|key, value|
# Determine if we can create a search link from this data
if (p_createLink && !key.nil? && !v_searchParam.nil?)
v_create_link=true
else
v_create_link=false
end
if (p_average)
v_value = (value[1]/value[2]).round(1)
else
v_value = value[1]
end
v_key = key.nil? ? "Not Listed" : key
v_dataTarget = "#" + v_key.gsub(" ","")
v_myID = p_parentTarget
p_array.push({"display_value"=>v_key, "sum_or_avg_of_children" => v_value, "number_of_children"=> value[2], "level"=> p_level, "create_link"=>v_create_link, "search_param"=>v_searchParam, "data_target"=>v_dataTarget, "myID"=>v_myID})
if !value[0].empty?
p_level = p_level + 1
p_array = create_array_from_hash(value[0], p_array, p_level, p_average, p_createLink, p_searchParams, v_dataTarget)
p_level = p_level -1
end
}
return p_array
end