Class: Languages::Ruby::ConditionalRuby

Inherits:
Conditional show all
Defined in:
lib/kuniri/language/ruby/conditional_ruby.rb

Overview

Class responsible for handling ruby conditional statements.

Instance Method Summary collapse

Instance Method Details

#conditional_type(pString) ⇒ Object (protected)

Override



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/kuniri/language/ruby/conditional_ruby.rb', line 55

def conditional_type(pString)
  regexExp = /^\s+if|^if/
  return Languages::IF_LABEL if regexExp =~ pString

  regexExp = /^\s+case|^case/
  return Languages::CASE_LABEL if regexExp =~ pString

  regexExp = /^\s+when|^when/
  return Languages::WHEN_LABEL if regexExp =~ pString

  regexExp = /^\s+unless|^unless/
  return Languages::UNLESS_LABEL if regexExp =~ pString

  regexExp = /^\s+elsif|^elsif/
  return Languages::ELSIF_LABEL if regexExp =~ pString

  regexExp = /^\s+else|^else/
  return Languages::ELSE_LABEL if regexExp =~ pString

  return nil
end

#detect_conditional(pLine) ⇒ Object (protected)

Override.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kuniri/language/ruby/conditional_ruby.rb', line 32

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*when\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

  regexExp = /^\s*else\s*/
  return pLine.scan(regexExp)[0].gsub(" ", "") if regexExp =~ pLine

  return nil
end

#get_conditional(pLine) ⇒ Object

Get ruby conditional.

See Also:



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kuniri/language/ruby/conditional_ruby.rb', line 16

def get_conditional(pLine)
  result = detect_conditional(pLine)
  return nil unless result

  conditionalCaptured = Languages::ConditionalData.new
  conditionalCaptured.type = conditional_type(pLine)
  unless conditionalCaptured.type == Languages::ELSE_LABEL
    conditionalCaptured.expression = get_expression(result)
  end

  return conditionalCaptured
end

#get_expression(pString) ⇒ Object (protected)

Override



78
79
80
81
82
# File 'lib/kuniri/language/ruby/conditional_ruby.rb', line 78

def get_expression(pString)
  leftStrip = pString.lstrip
  rightStrip = leftStrip.rstrip
  return rightStrip
end