Class: Udup
- Inherits:
-
Object
- Object
- Udup
- Defined in:
- lib/udup/main.rb
Instance Method Summary collapse
- #filter(urls) ⇒ Object
-
#initialize(options = {}) ⇒ Udup
constructor
A new instance of Udup.
Constructor Details
#initialize(options = {}) ⇒ Udup
Returns a new instance of Udup.
7 8 9 10 11 12 13 |
# File 'lib/udup/main.rb', line 7 def initialize( = {}) @valid_urls = {} @skip_exts = [:skip_exts] || %w[.css .png .jpg .jpeg .svg .ico .webp .ttf .otf .woff .woff2 .gif .pdf .bmp .eot .mp3 .mp4 .avi] @content_to_skip = %r{blog|docs|post|support|pages?/\d+|articles?/\d+|share\/\w{15,}|\d{2,}}i @bad_char_path = [:bad_char_path] || %w[+ ' " ( ) \\ <] end |
Instance Method Details
#filter(urls) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/udup/main.rb', line 15 def filter(urls) final_urls = Set[] urls.each do |url| next unless url.start_with?('http') begin uri = URI.parse(url) rescue URI::InvalidURIError next end next unless uri next if @bad_char_path.any? { |char| uri.path.include?(char) } uri_ext = File.extname(uri.path) next if @skip_exts.include?(uri_ext) || human_content?(uri.path) || content_to_skip?(uri.path) base_url = without_query(uri) params = uri_params(uri.query) if @valid_urls.key?(base_url) @valid_urls[uri.to_s] = { params: {} } if @valid_urls[base_url][:params].empty? @valid_urls[base_url][:params].merge!(params) else @valid_urls[base_url] = { params: params } end end @valid_urls.each do |url, data| final_url = url final_url += "?#{URI.encode_www_form(data[:params])}" unless data[:params].empty? final_urls << final_url end final_urls.to_a end |