Class: RuboCop::Slim::KeywordRemover

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

Overview

Remove unnecessary part (e.g. ‘if`, `unless`, `do`, …) from Ruby-ish code.

Defined Under Namespace

Classes: PrecedingKeywordRemover, TrailingDoRemover

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruby_clip) ⇒ KeywordRemover

Returns a new instance of KeywordRemover.

Parameters:

  • ruby_clip (String)


16
17
18
# File 'lib/rubocop/slim/keyword_remover.rb', line 16

def initialize(ruby_clip)
  @ruby_clip = ruby_clip
end

Class Method Details

.call(ruby_clip) ⇒ RuboCop::Slim::RubyClip

Parameters:

Returns:



10
11
12
# File 'lib/rubocop/slim/keyword_remover.rb', line 10

def call(ruby_clip)
  new(ruby_clip).call
end

Instance Method Details

#callRuboCop::Slim::RubyClip



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rubocop/slim/keyword_remover.rb', line 21

def call
  [
    PrecedingKeywordRemover,
    TrailingDoRemover
  ].reduce(@ruby_clip) do |previous, callable|
    result = callable.call(previous.code)
    RubyClip.new(
      code: result.code,
      offset: previous.offset + result.offset
    )
  end
end