Sha256: 1199e9583e8618f488416a8e9e8cd094c7f5bfdee870344f1f65884db41fa500

Contents?: true

Size: 969 Bytes

Versions: 13

Compression:

Stored size: 969 Bytes

Contents

# frozen_string_literal: true

require "oga"

module Miteru
  class Website
    attr_reader :url
    def initialize(url)
      @url = url
    end

    def title
      doc.at_css("title")&.text
    end

    def compressed_files
      @compressed_files ||= doc.css("a").map do |a|
        href = a.get("href")
        [".zip", ".rar", ".7z", ".tar", ".gz"].any? { |ext| href&.end_with? ext } ? href : nil
      end.compact.map do |href|
        href.start_with?("/") ? href[1..-1] : href
      end
    end

    def ok?
      response.code == 200
    end

    def index?
      title == "Index of /"
    end

    def compressed_files?
      !compressed_files.empty?
    end

    def has_kit?
      ok? && index? && compressed_files?
    rescue StandardError => _
      false
    end

    private

    def response
      @response ||= get
    end

    def get
      HTTPClient.get url
    end

    def doc
      @doc ||= Oga.parse_html(response.body.to_s)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
miteru-0.12.0 lib/miteru/website.rb
miteru-0.11.3 lib/miteru/website.rb
miteru-0.11.2 lib/miteru/website.rb
miteru-0.11.1 lib/miteru/website.rb
miteru-0.11.0 lib/miteru/website.rb
miteru-0.10.2 lib/miteru/website.rb
miteru-0.10.1 lib/miteru/website.rb
miteru-0.10.0 lib/miteru/website.rb
miteru-0.9.6 lib/miteru/website.rb
miteru-0.9.5 lib/miteru/website.rb
miteru-0.9.4 lib/miteru/website.rb
miteru-0.9.3 lib/miteru/website.rb
miteru-0.9.2 lib/miteru/website.rb