Class: Slimcop::RubyExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/slimcop/ruby_extractor.rb

Overview

Extract Ruby codes from Slim source.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path:, source:) ⇒ RubyExtractor

Returns a new instance of RubyExtractor.

Parameters:

  • file_path (String, nil)
  • source (String)


25
26
27
28
# File 'lib/slimcop/ruby_extractor.rb', line 25

def initialize(file_path:, source:)
  @file_path = file_path
  @source = source
end

Class Method Details

.call(file_path:, source:) ⇒ Object

Parameters:

  • file_path (String, nil)
  • source (String)


12
13
14
15
16
17
18
19
20
# File 'lib/slimcop/ruby_extractor.rb', line 12

def call(
  file_path:,
  source:
)
  new(
    file_path: file_path,
    source: source
  ).call
end

Instance Method Details

#callArray<Hash>

Returns:

  • (Array<Hash>)


31
32
33
34
35
36
37
38
39
# File 'lib/slimcop/ruby_extractor.rb', line 31

def call
  ranges.map do |(begin_, end_)|
    clipped = ::Templatecop::RubyClipper.new(@source[begin_...end_]).call
    {
      code: clipped[:code],
      offset: begin_ + clipped[:offset]
    }
  end
end