Skip to content

Commit

Permalink
Merge 354872c into 8d361a6
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Jun 23, 2020
2 parents 8d361a6 + 354872c commit 9f1a570
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/miteru/feeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
module Miteru
class Feeds
IGNORE_EXTENSIONS = %w(.htm .html .php .asp .aspx .exe .txt).freeze
VALID_EXTENSIONS = [".zip", ".rar", ".7z", ".tar", ".gz"].freeze

def initialize
@feeds = [
Expand Down Expand Up @@ -48,7 +49,17 @@ def breakdown(url)
segments = uri.path.split("/")
return [base] if segments.length.zero?

urls = (0...segments.length).map { |idx| "#{base}#{segments[0..idx].join('/')}" }
urls = (0...segments.length).map do |idx|
breakdowned_url = "#{base}#{segments[0..idx].join('/')}"
breakdown = [breakdowned_url]
if idx > 0 && idx < segments.length - 1
VALID_EXTENSIONS.each do |ext|
breakdown << "#{base}#{segments[0..idx - 1].join('/')}/#{segments[idx]}#{ext}"
end
end
breakdown
end.flatten

urls.reject do |breakdowned_url|
# Reject a url which ends with specific extension names
invalid_extension? breakdowned_url
Expand Down
2 changes: 1 addition & 1 deletion spec/feeds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

it do
results = subject.new.breakdown("http://test.com/test/test/index.html")
expect(results).to eq(["http://test.com", "http://test.com/test", "http://test.com/test/test"])
expect(results).to eq(["http://test.com", "http://test.com/test", "http://test.com/test.zip", "http://test.com/test.rar", "http://test.com/test.7z", "http://test.com/test.tar", "http://test.com/test.gz", "http://test.com/test/test", "http://test.com/test/test.zip", "http://test.com/test/test.rar", "http://test.com/test/test.7z", "http://test.com/test/test.tar", "http://test.com/test/test.gz"])
end
end
end
Expand Down

0 comments on commit 9f1a570

Please sign in to comment.