lib/inch/language/elixir/provider/reader/object/function_object.rb in inch-0.5.0.rc8 vs lib/inch/language/elixir/provider/reader/object/function_object.rb in inch-0.5.0.rc9

- old
+ new

@@ -1,5 +1,7 @@ +require 'inch/language/elixir/provider/reader/object/function_parameter_object' + module Inch module Language module Elixir module Provider module Reader @@ -14,9 +16,31 @@ @hash['module_id'] + '.' + @hash['id'] end def method? true + end + + def parameters + names = FunctionSignature.new(name, @hash['signature']).parameter_names + names.map do |name| + FunctionParameterObject.new(self, name) + end + end + + private + + class FunctionSignature < Struct.new(:fun_name, :signature) + def parameter_names + base_name = fun_name.split('/').first + signature.gsub(/^(#{base_name}\()/, '').gsub(/(\))$/, '') + .gsub( /\([^\)]+\)/, '' ) + .split(',') + .map do |param| + name = param.split("\\\\").first + name && name.strip + end.compact + end end end end end end