Sha256: 8ad4fbcca9584886a390fc1a30a882b3045c80d6ca9b8fbbde9af81ce43b2477

Contents?: true

Size: 812 Bytes

Versions: 2

Compression:

Stored size: 812 Bytes

Contents

# frozen_string_literal: true

require "oga"

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

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

    def zip_files
      @zip_files ||= doc.css("a").map do |a|
        href = a.get("href")
        href&.end_with?(".zip") ? href : nil
      end.compact
    end

    def ok?
      response.code == 200
    end

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

    def zip_files?
      !zip_files.empty?
    end

    def has_kit?
      ok? && index? && zip_files?
    end

    def build
      doc
    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

2 entries across 2 versions & 1 rubygems

Version Path
miteru-0.4.0 lib/miteru/website.rb
miteru-0.3.2 lib/miteru/website.rb