Class: RuboCop::Haml::RubyClipper

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/haml/ruby_clipper.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(code) ⇒ RubyClipper

Returns a new instance of RubyClipper.

Parameters:

  • code (String)


16
17
18
# File 'lib/rubocop/haml/ruby_clipper.rb', line 16

def initialize(code)
  @code = code
end

Class Method Details

.call(code) ⇒ Hash

Parameters:

  • code (String)

Returns:

  • (Hash)


10
11
12
# File 'lib/rubocop/haml/ruby_clipper.rb', line 10

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

Instance Method Details

#callRuboCop::Haml::RubyClip



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubocop/haml/ruby_clipper.rb', line 21

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