-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathactor_list.rb
executable file
·189 lines (146 loc) · 3.73 KB
/
actor_list.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/ruby
# = actor_list.rb: retrieve <<actor>> classes from the xml
#
# Author:: tckz <[email protected]>
# http://passing.breeze.cc/
$KCODE='u'
require 'optparse'
require 'ostruct'
require 'pp'
$:.unshift(File.join(File.dirname(__FILE__), "lib"))
require 'jude_util'
require 'xml_util'
module JudeUtil
class ActorList
include JudeUtil
def initialize(root, options)
@root = root
@options = options
end
def out_list(io)
self.actor_list.each { |cols|
self.esc_out(cols, io)
}
end
# アクターリスト
def actor_list()
lines = []
acs = self.select_target(@root, "//class[./stereotypes/stereotype[text()='actor']]", @options).find_all { |e|
!(self.find_annotations(e, "@key='@noest'").size > 0)
}
parent_pkgs = {}
acs.each { |ac|
name = self.get_name(ac)
fullname = self.get_fullname(ac)
namespace = self.get_namespace(ac)
if namespace != "" && !parent_pkgs[namespace]
pkg = self.get_parent(ac)
if [email protected]_pkg
lines.push(
[
namespace,
"", namespace, namespace,
# APIの仕様でパッケージ配下の図中のコメントが紐づくので「定義」のみに絞る
self.make_desc(pkg, "\n--\n", true),
"",
]
)
end
parent_pkgs[namespace] = pkg
end
desc = self.make_desc(ac, "\n--\n", @options.definition_only)
# ユースケースポイント用の「係数」
factor = nil
el_an = self.find_annotations(ac, "@key='@factor'").first
if el_an
factor = el_an.child.to_s.strip
end
lines.push(
[
"",
name, namespace, fullname,
desc,
factor
]
)
}
lines
end
#
# argv::
# ARGV
def self.main(argv)
options = OpenStruct.new
options.encode = "utf-8"
options.since = nil
options.fn_out = nil
options.use_alias1 = nil
options.fullname = nil
options.definition_only = nil
options.wo_pkg = false
# オプション
OptionParser.new { |opt|
opt.banner = "usage: #{File.basename($0)} [options] [in.xml]"
opt.separator ""
opt.separator " o retrieve actor-list"
opt.separator " o use STDIN instead of file if in.xml was ommited."
opt.separator ""
opt.separator "Options:"
opt.on("--definition-only", "the desc looked up from only definition") do |v|
options.definition_only = true
end
opt.on("--without-package", "exclude package info") do |v|
options.wo_pkg = true
end
opt.on("-e", "--encoding=ENCODING-NAME", "default: #{options.encode}") do |v|
options.encode = v
end
opt.on("-f", "--fullname=REGEX", "criteria for fullname") do |v|
options.fullname = v
end
opt.on("-o", "--out=FILENAME", "filename for output") do |v|
options.fn_out = v
end
opt.on("-s", "--since=REGEX", "criteria for @since") do |v|
options.since = v
end
opt.on("-a", "--use-alias1", "use alias1 to identifiers") do |v|
options.use_alias1 = true
end
begin
opt.parse!(argv)
rescue ArgumentError, OptionParser::ParseError => e
STDERR.puts opt.to_s
STDERR.puts ""
STDERR.puts "#{e.message}"
return 1
end
}
fn_in = argv[0]
doc = XMLUtil::XML::build_document(fn_in)
fp_out = nil
begin
if options.fn_out
io_out = fp_out = File.new(options.fn_out, "w")
else
io_out = STDOUT
end
io_out.extend(TextConverter).from_to("utf-8", options.encode)
ul = JudeUtil::ActorList.new(doc.root, options)
ul.out_list(io_out)
ensure
if fp_out
fp_out.close
end
end
0
end
end
end
if $0 == __FILE__
include JudeUtil
include XMLUtil::XML
Version = JudeUtil::Version
exit JudeUtil::ActorList::main(ARGV)
end
# vi: ts=2 sw=2