/
common.rb
82 lines (70 loc) · 2 KB
/
common.rb
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class Common
class <<self
def load_config(file="#{ENV['HOME']}/.conf.rb")
config = {}
File.open(file) do |f|
# puts f.readlines.join('')
config = eval(f.readlines.join(''))
end
config
end
@@rally_types = {
:tags => :tag,
:ta => :task,
:tas => :task,
:de => :defect,
:des => :defect,
:us => :hierarchical_requirement
}
@@escapes ={
#tags
"<br[ /]*>" => "\n",
"<div[ \\w='\";&-:_]*>" => "",
"</div>" => "\n",
"<p[ \\w='\";&-:_]*>" => "",
"</p>" => "\n",
"</?span[ \\w='\";&-:_]*>" => "",
"</?u>" => '',
# html escapes
'>' => '>',
'<' => '<',
" " => ' '
}
def escape(string)
changed = string
@@escapes.each do |k,v|
changed = changed.gsub(/#{k}/,v)
end
changed
end
def std_tags(obj,prefix='',postfix="\n")
"#{prefix}#{obj.tags.join(', ')}#{postfix}" if obj.tags.size > 0
end
def std_rank(obj)
obj.rank || '---'
end
def std_hierarchical_requirement(us)
escape "#{std_rank(us)} #{us.formatted_i_d} #{us.schedule_state} #{us.owner} #{us.name}"
end
def std_task(ta)
escape "#{std_rank(ta)} #{ta.formatted_i_d}(#{ta.work_product.formatted_i_d}) #{ta.state} #{ta.owner} #{ta.name}"
end
def std_defect(de)
str = escape "#{std_rank(de)} #{de.formatted_i_d} #{de.priority} #{de.schedule_state} #{de.state} #{de.owner}\n"
str += std_tags(de,"\t")
str += "\t#{de.name}"
end
def std_tag(tag)
escape tag.name
end
def rally_type(type)
@@rally_types[type.to_sym] || type
end
def can_render?(type)
self.respond_to? "std_#{rally_type(type)}"
end
def render(type,obj)
Common.send("std_#{rally_type(type)}".to_sym,obj) if can_render?(type)
end
end
end