Class: RuboCop::Erb::KeywordRemover::PrecedingKeywordRemover

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/erb/keyword_remover.rb

Overview

Remove preceding keyword.

Constant Summary collapse

REGEXP =
/
  \A
  \s*
  (?:
    begin
    | case
    | else
    | elsif
    | end
    | ensure
    | if
    | rescue
    | unless
    | until
    | when
    | while
    | for[ \t]+\w+[ \t]+in
  )
  [ \t]
/x.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ PrecedingKeywordRemover

Returns a new instance of PrecedingKeywordRemover.

Parameters:

  • code (String)


66
67
68
# File 'lib/rubocop/erb/keyword_remover.rb', line 66

def initialize(code)
  @code = code
end

Class Method Details

.call(code) ⇒ RubyClip

Parameters:

  • code (String)

Returns:



60
61
62
# File 'lib/rubocop/erb/keyword_remover.rb', line 60

def call(code)
  new(code).call
end

Instance Method Details

#callHash

Returns:

  • (Hash)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rubocop/erb/keyword_remover.rb', line 71

def call
  data = @code.match(REGEXP)
  if data
    offset = data[0].length
    RubyClip.new(
      code: @code[offset..],
      offset: offset
    )
  else
    RubyClip.new(
      code: @code,
      offset: 0
    )
  end
end