Module: RD::MethodParse

Included in:
RD2HTMLVisitor, RD2MANVisitor, RD2RMIVisitor
Defined in:
lib/rd2odt/rdtool/rd/rdvisitor.rb

Overview

module RD::MethodParse

this module provide several functions for MehotList.

Constant Summary collapse

KIND2NUM =
{:constant => 0, :class_method => 1, :instance_method => 2, :function => 2}

Class Method Summary collapse

Class Method Details

.analize_method(method) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rd2odt/rdtool/rd/rdvisitor.rb', line 58

def analize_method(method)
  klass = nil
  args = nil
  kind = nil
  if /[^{(\s]+/ =~ method
	method = $&
	args = $'                   # '
  end

  if /^(.*)(#|::|\.)/ =~ method
	klass = $1
	kind = str2kind($2)
	method = $'                 # '
  end
  
  if klass == "function" and kind == :instance_method
	kind = :function
  end
  
  [klass, kind, method, args]
end

.kind2num(str) ⇒ Object



106
107
108
# File 'lib/rd2odt/rdtool/rd/rdvisitor.rb', line 106

def kind2num(str)
  KIND2NUM[str]
end

.kind2str(int) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/rd2odt/rdtool/rd/rdvisitor.rb', line 93

def kind2str(int)
  case int
  when :instance_method, :function
	'#'
  when :class_method
	'.'
  when :constant
	'::'
  end
end

.make_method_index(tree) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
# File 'lib/rd2odt/rdtool/rd/rdvisitor.rb', line 192

def make_method_index(tree)
  indexes = []
  tree.each do |i|
	if i.is_a?(MethodListItem)
	  klass, kind, method, args = analize_method(i.term.content)
	  indexes.push([klass, kind2num(kind), method, kind]) if kind
	end
  end
  indexes.uniq!
  indexes.sort.each {|i| i[1] = i.pop}
end

.make_mindex_label(element) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rd2odt/rdtool/rd/rdvisitor.rb', line 111

def make_mindex_label(element)
  klass, kind, method = analize_method(element.label)
  case kind
  when :class_method
	klass + "_S_" + tr_method(method)
  when :instance_method
	klass + "_" + tr_method(method)
  when :constant
	klass + "_" + method
  when :function
	"function_" + tr_method(method)
  else
	element.label
  end
end

.str2kind(str) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/rd2odt/rdtool/rd/rdvisitor.rb', line 81

def str2kind(str)
  case str
  when '#'
	:instance_method
  when '.'
	:class_method
  when '::'
	:constant
  end
end

.tr_method(method) ⇒ Object



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
189
# File 'lib/rd2odt/rdtool/rd/rdvisitor.rb', line 128

def tr_method(method)
  case method
  when "[]"
	"ref_"
  when "[]="
	"set_"
  when "+"
	"plus_"
  when "+@"
	"uplus_"
  when "-"
	"minus_"
  when "-@"
	"uminus_"
  when "*"
	"mul_"
  when "/"
	"div_"
  when "%"
    "mod_"
  when "**"
	"power_"
  when "~"
	"inv_"
  when "=="
	"eq_"
  when "==="
	"eqq_"
  when "=~"
	"match_"
  when "&"
	"and_"
  when "|"
	"or_"
  when "<<"
	"lshift_"
  when ">>"
	"rshift_"
  when "<=>"
	"cmp_"
  when "<"
	"lt_"
  when "<="
	"le_"
  when ">"
	"gt_"
  when ">="
	"ge_"
  when "^"
	"xor_"
  when "`"
	"backquote_"
  when /!$/
	$` + "_bang"     # `
  when /\?$/
	$` + "_p"        # `
  when /=$/
	$` + "_eq"       # `
  else
	method
  end
end