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 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 14 def initialize end |
Instance Method Details
#detect_function(pLine) ⇒ Object (protected)
Override
37 38 39 40 41 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 37 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.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 18 def get_function(pLine, type = 'globalFunction') result = detect_function(pLine) return nil unless result functionRuby = Languages::FunctionData.new(result) parameters = handling_parameter(pLine) if parameters parameters.each do |parameter| functionRuby.add_parameters(parameter) end end return functionRuby end |
#handling_default_parameter(pLine) ⇒ Object (protected)
Override
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 44 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 = {parameter => value} newList.push(defaultParameter) next end newList.push(element) end return newList end |
#handling_parameter(pLine) ⇒ Object (protected)
Override
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 76 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
70 71 72 73 |
# File 'lib/kuniri/language/ruby/function_behavior_ruby.rb', line 70 def remove_unnecessary_information(pLine) return pLine.gsub(/\s+|\(|\)/,"") if pLine =~ /\s+|\(|\)/ return pLine end |