push
travis-ci
52 of 52 new or added lines in 5 files covered. (100.0%)
100 of 115 relevant lines covered (86.96%)
1.9 hits per line
1 |
# frozen_string_literal: true
|
|
2 |
|
|
|
require "http"
|
1✔ |
|
require "oga"
|
1✔ |
5 |
|
|
|
module Miteru |
1✔ |
|
class Website |
1✔ |
|
attr_reader :url
|
1✔ |
|
def initialize(url) |
1✔ |
|
@url = url
|
3✔ |
11 |
end
|
|
12 |
|
|
|
def title |
1✔ |
|
doc.at_css("title")&.text
|
2✔ |
15 |
end
|
|
16 |
|
|
|
def zip_files |
1✔ |
|
@zip_files ||= doc.css("a").map do |a| |
1✔ |
|
href = a.get("href")
|
4✔ |
|
href&.end_with?(".zip") ? href : nil |
4✔ |
21 |
end.compact
|
|
22 |
end
|
|
23 |
|
|
|
def index? |
1✔ |
|
title == "Index of /"
|
2✔ |
26 |
end
|
|
27 |
|
|
|
def zip_files? |
1✔ |
|
!zip_files.empty? |
1✔ |
30 |
end
|
|
31 |
|
|
|
def has_kit? |
1✔ |
|
index? && zip_files? |
2✔ |
34 |
end
|
|
35 |
|
|
|
private |
1✔ |
37 |
|
|
|
def get |
1✔ |
|
res = HTTP.get(url)
|
× |
|
raise HTTPResponseError if res.code != 200 |
× |
41 |
|
|
|
res.body.to_s |
× |
43 |
end
|
|
44 |
|
|
|
def doc |
1✔ |
|
@doc ||= Oga.parse_html(get) |
3✔ |
47 |
end
|
|
48 |
end
|
|
49 |
end
|