module RD::MethodParse
module RD::MethodParse
¶ ↑
this module provide several functions for MehotList.
Constants
- KIND2NUM
Public Class Methods
analize_method(method)
click to toggle source
# File lib/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)
click to toggle source
# File lib/rd/rdvisitor.rb, line 106 def kind2num(str) KIND2NUM[str] end
kind2str(int)
click to toggle source
# File lib/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)
click to toggle source
# File lib/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)
click to toggle source
# File lib/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)
click to toggle source
# File lib/rd/rdvisitor.rb, line 81 def str2kind(str) case str when '#' :instance_method when '.' :class_method when '::' :constant end end
tr_method(method)
click to toggle source
# File lib/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
Private Instance Methods
analize_method(method)
click to toggle source
# File lib/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)
click to toggle source
# File lib/rd/rdvisitor.rb, line 106 def kind2num(str) KIND2NUM[str] end
kind2str(int)
click to toggle source
# File lib/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)
click to toggle source
# File lib/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)
click to toggle source
# File lib/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)
click to toggle source
# File lib/rd/rdvisitor.rb, line 81 def str2kind(str) case str when '#' :instance_method when '.' :class_method when '::' :constant end end
tr_method(method)
click to toggle source
# File lib/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