Class: JsDependency::Extractor::ExtractSrcPath
- Inherits:
-
Object
- Object
- JsDependency::Extractor::ExtractSrcPath
- Defined in:
- lib/js_dependency/extractor/extract_src_path.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ Array<String>
Extract JavaScript file (.js) in src path.
-
#initialize(str) ⇒ ExtractSrcPath
constructor
A new instance of ExtractSrcPath.
Constructor Details
#initialize(str) ⇒ ExtractSrcPath
Returns a new instance of ExtractSrcPath.
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
#call ⇒ Array<String>
Extract JavaScript file (.js) in src path
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 |