Class: Languages::Ruby::FunctionBehaviorRuby
- Inherits:
-
FunctionBehavior
- Object
- FunctionBehavior
- Languages::Ruby::FunctionBehaviorRuby
- Defined in:
- lib/kuniri/language/ruby/function_behavior_ruby.rb
Overview
Handling Ruby method
Direct Known Subclasses
Instance Method Summary collapse
-
#detect_function(pLine) ⇒ Object
protected
Override.
-
#get_function(pLine, type = 'globalFunction') ⇒ Object
Get Ruby function.
-
#handling_default_parameter(pLine) ⇒ Object
protected
Override.
-
#handling_parameter(pLine) ⇒ Object
protected
Override.
-
#initialize ⇒ FunctionBehaviorRuby
constructor
A new instance of FunctionBehaviorRuby.
-
#remove_unnecessary_information(pLine) ⇒ Object
protected
Override.
Constructor Details
#initialize ⇒ FunctionBehaviorRuby
Returns a new instance of FunctionBehaviorRuby.
14 15 16 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 14 def initialize @log = @settings = Kuniri::Setting.create.log end |
Instance Method Details
#detect_function(pLine) ⇒ Object (protected)
Override
43 44 45 46 47 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 43 def detect_function(pLine) regexExpression = /^\s*def\b\s*(\w*)\b/ return nil unless pLine =~ regexExpression return pLine.scan(regexExpression)[0].join("") end |
#get_function(pLine, type = 'globalFunction') ⇒ Object
Get Ruby function.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 19 def get_function(pLine, type = 'globalFunction') result = detect_function(pLine) return nil unless result @log.write_log("Info: get method") functionRuby = Languages::FunctionData.new(result) parameters = handling_parameter(pLine) if parameters parameters.each do |parameter| functionRuby.add_parameters(parameter) end end @log.write_log("Debug: Method: #{functionRuby.name}, Parameter: #{functionRuby.parameters}") return functionRuby end |
#handling_default_parameter(pLine) ⇒ Object (protected)
Override
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 50 def handling_default_parameter(pLine) return pLine unless pLine =~ /=/ if pLine =~ /,/ partialParameters = pLine.split(",") else partialParameters = [pLine] end newList = [] partialParameters.each do |element| if element =~ /=/ parameter = element.scan(/(\w*)=/).join("") value = element.scan(/=(\w*)/).join("") defaultParameter = Hash(parameter => value) newList.push(defaultParameter) next end newList.push(element) end return newList end |
#handling_parameter(pLine) ⇒ Object (protected)
Override
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 82 def handling_parameter(pLine) # Handling with parenthesis and without it. if pLine =~ /\(.+\)/ partial = get_parameters(pLine, /\(.+\)/) elsif pLine =~ /def\s+\w+[\s]+(.+)/ partial = get_parameters(pLine, /def\s+\w+[\s]+(.+)/) else return nil end return handling_default_parameter(partial) if partial =~ /=/ return split_string_by_comma(partial) end |
#remove_unnecessary_information(pLine) ⇒ Object (protected)
Override
76 77 78 79 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 76 def remove_unnecessary_information(pLine) return pLine.gsub(/\s+|\(|\)/,"") if pLine =~ /\s+|\(|\)/ return pLine end |