Class: Slimi::Filters::EndInserter::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/slimi/filters/end_inserter.rb

Constant Summary collapse

IF_REGEXP =
/\A(if|begin|unless|else|elsif|when|rescue|ensure)\b|\bdo\s*(\|[^|]*\|)?\s*$/.freeze
ELSE_REGEXP =
/\A(else|elsif|when|rescue|ensure)\b/.freeze
END_REGEXP =
/\Aend\b/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(expression) ⇒ Expression

Returns a new instance of Expression.

Parameters:

  • expression (Array)


46
47
48
# File 'lib/slimi/filters/end_inserter.rb', line 46

def initialize(expression)
  @expression = expression
end

Instance Method Details

#control?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/slimi/filters/end_inserter.rb', line 51

def control?
  @expression[0] == :slimi && @expression[1] == :control
end

#else?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/slimi/filters/end_inserter.rb', line 61

def else?
  @expression[2].match?(ELSE_REGEXP)
end

#end?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/slimi/filters/end_inserter.rb', line 66

def end?
  @expression[2].match?(END_REGEXP)
end

#if?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/slimi/filters/end_inserter.rb', line 56

def if?
  @expression[2].match?(IF_REGEXP)
end

#newline?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/slimi/filters/end_inserter.rb', line 71

def newline?
  @expression[0] == :newline
end