Class: JsDependency::Extractor::ExtractSrcPath

Inherits:
Object
  • Object
show all
Defined in:
lib/js_dependency/extractor/extract_src_path.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ ExtractSrcPath

Returns a new instance of ExtractSrcPath.

Parameters:

  • str (String)


7
8
9
# File 'lib/js_dependency/extractor/extract_src_path.rb', line 7

def initialize(str)
  @str = str
end

Class Method Details

.call(str) ⇒ Object



22
23
24
# File 'lib/js_dependency/extractor/extract_src_path.rb', line 22

def self.call(str)
  new(str).call
end

Instance Method Details

#callArray<String>

Extract JavaScript file (.js) in src path

Returns:

  • (Array<String>)


13
14
15
16
17
18
19
20
# File 'lib/js_dependency/extractor/extract_src_path.rb', line 13

def call
  str = @str
  # <script src="module-name.js">
  paths = str.gsub(/<script\s+src="([^']+)">/).with_object([]) { |_, list| list << Regexp.last_match(1) }
  paths += str.gsub(/<script\s+src='([^']+)'>/).with_object([]) { |_, list| list << Regexp.last_match(1) }

  filter_javascript_paths(paths).uniq.sort
end