Class: Languages::Ruby::ConditionalRuby
- Inherits:
-
Conditional
- Object
- Conditional
- Languages::Ruby::ConditionalRuby
- Defined in:
- lib/kuniri/language/ruby/conditional_ruby.rb
Overview
Class responsible for handling ruby conditional statements.
Instance Method Summary collapse
-
#conditional_type(pString) ⇒ Object
protected
Override.
-
#detect_conditional(pLine) ⇒ Object
protected
Override.
-
#get_conditional(pLine) ⇒ Object
Get ruby conditional.
-
#get_expression(pString) ⇒ Object
protected
Override.
Instance Method Details
#conditional_type(pString) ⇒ Object (protected)
Override
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/kuniri/language/ruby/conditional_ruby.rb', line 47 def conditional_type(pString) regexExp = /^\s+if|^if/ return "IF" if regexExp =~ pString regexExp = /^\s+case|^case/ return "CASE" if regexExp =~ pString regexExp = /^\s+unless|^unless/ return "UNLESS" if regexExp =~ pString regexExp = /^\s+elsif|^elsif/ return "ELSIF" if regexExp =~ pString return nil end |
#detect_conditional(pLine) ⇒ Object (protected)
Override.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kuniri/language/ruby/conditional_ruby.rb', line 30 def detect_conditional(pLine) regexExp = /^\s*if\s+(.*)/ return pLine.scan(regexExp)[0].join("") if regexExp =~ pLine regexExp = /^\s*case\s+(.*)/ return pLine.scan(regexExp)[0].join("") if regexExp =~ pLine regexExp = /^\s*unless\s+(.*)/ return pLine.scan(regexExp)[0].join("") if regexExp =~ pLine regexExp = /^\s*elsif\s+(.*)/ return pLine.scan(regexExp)[0].join("") if regexExp =~ pLine return nil end |
#get_conditional(pLine) ⇒ Object
Get ruby conditional.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/kuniri/language/ruby/conditional_ruby.rb', line 15 def get_conditional(pLine) result = detect_conditional(pLine) return nil unless result conditionalCaptured = Languages::ConditionalData.new conditionalCaptured.type = conditional_type(pLine) conditionalCaptured.expression = get_expression(result) return conditionalCaptured end |
#get_expression(pString) ⇒ Object (protected)
Override
64 65 66 67 68 |
# File 'lib/kuniri/language/ruby/conditional_ruby.rb', line 64 def get_expression(pString) leftStrip = pString.lstrip rightStrip = leftStrip.rstrip return rightStrip end |