Sha256: 0cfef2b47e4bb7b976093990384055e6099ff0600b66c6181368934185782c6c

Contents?: true

Size: 449 Bytes

Versions: 1

Compression:

Stored size: 449 Bytes

Contents

# frozen_string_literal: true

module JsDependency
  class ExtractScriptTag
    # @param [String] str
    def initialize(str)
      @str = str
    end

    # @return [Array<String>]
    def call
      str = @str
      scripts = str.gsub(%r{<script.*>(.+)</script>}m).with_object([]) do |_, list|
        list << Regexp.last_match(1)
      end

      scripts.uniq.sort.join("\n")
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
js_dependency-0.2.3 lib/js_dependency/extract_script_tag.rb