Class: Miteru::Website

Inherits:
Service show all
Includes:
Concerns::UrlTruncatable
Defined in:
lib/miteru/website.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::UrlTruncatable

#decoded_url, #defanged_truncated_url, #truncated_url

Methods inherited from Service

#call, call, #result, result

Constructor Details

#initialize(url, source:) ⇒ Website

Returns a new instance of Website.

Parameters:

  • url (String)
  • source (String)


19
20
21
22
23
24
# File 'lib/miteru/website.rb', line 19

def initialize(url, source:)
  super()

  @url = url
  @source = source
end

Instance Attribute Details

#sourceString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/miteru/website.rb', line 13

def source
  @source
end

#urlString (readonly)

Returns:

  • (String)


10
11
12
# File 'lib/miteru/website.rb', line 10

def url
  @url
end

Instance Method Details

#index?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/miteru/website.rb', line 34

def index?
  title.to_s.start_with? "Index of"
end

#infoObject



46
47
48
# File 'lib/miteru/website.rb', line 46

def info
  "#{defanged_truncated_url} has #{kits.length} kit(s) (Source: #{source})"
end

#kitsObject



30
31
32
# File 'lib/miteru/website.rb', line 30

def kits
  @kits ||= links.map { |link| Kit.new(link, source:) }.select(&:valid?)
end

#kits?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/miteru/website.rb', line 38

def kits?
  kits.any?
end


42
43
44
# File 'lib/miteru/website.rb', line 42

def links
  (href_links + possible_file_links).compact.uniq
end

#titleObject



26
27
28
# File 'lib/miteru/website.rb', line 26

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