Module: IrokiLib::Utils
- Includes:
- AbortIf, CoreExt::String
- Defined in:
- lib/iroki_lib/utils/utils.rb
Instance Method Summary
collapse
#clean, #clean_name, #has_color?, #hex?
Instance Method Details
#add_color_to_leaf_branch(patterns, node, exact) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/iroki_lib/utils/utils.rb', line 28
def add_color_to_leaf_branch patterns, node, exact
num_matches = 0
color = nil
already_matched = false
if exact node_s = node.to_s
if patterns.has_key? node_s
color = patterns[node_s]
return color
else
return nil
end
else
node_s = node.to_s
patterns.each do |pattern, this_color|
if node_s =~ pattern
abort_if already_matched,
"Non specific matching for #{node_s}"
color = this_color
already_matched = true
end
end
return color
end
end
|
#color_nodes(patterns, tree, node, exact) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/iroki_lib/utils/utils.rb', line 67
def color_nodes patterns, tree, node, exact
node.name = clean_name node.name
if leaf?(tree, node) && !already_checked?(node.name)
color = add_color_to_leaf_branch patterns, node, exact
node.name = node.name + color if color
elsif !leaf?(tree, node)
children = tree.children(node) children_colors = []
children.each do |child|
color_nodes patterns, tree, child, exact
children_colors << get_color(child) end
if children_colors.uniq.count == 1
node.name = children_colors[0]
end
end
return node
end
|
#get_color(node) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/iroki_lib/utils/utils.rb', line 59
def get_color node
begin
node.name.match(/\[&!color="#[0-9A-Fa-f]{6}"\]/)[0]
rescue NoMethodError => e
nil
end
end
|
#leaf?(tree, node) ⇒ Boolean
24
25
26
|
# File 'lib/iroki_lib/utils/utils.rb', line 24
def leaf? tree, node
tree.children(node).empty?
end
|