Sha256: 905a876ec8bec8a95dffabc3eb16f1fb15bd9e74e011a00603c05ba608abadb3

Contents?: true

Size: 496 Bytes

Versions: 6

Compression:

Stored size: 496 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

    # @param [String] str
    # @return [String]
    def self.call(str)
      new(str).call
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
js_dependency-0.3.5 lib/js_dependency/extract_script_tag.rb
js_dependency-0.3.4 lib/js_dependency/extract_script_tag.rb
js_dependency-0.3.3.1 lib/js_dependency/extract_script_tag.rb
js_dependency-0.3.3 lib/js_dependency/extract_script_tag.rb
js_dependency-0.3.2 lib/js_dependency/extract_script_tag.rb
js_dependency-0.3.1 lib/js_dependency/extract_script_tag.rb