Class: Miteru::Website

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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)


17
18
19
20
21
22
# File 'lib/miteru/website.rb', line 17

def initialize(url, source:)
  super()

  @url = url
  @source = source
end

Instance Attribute Details

#sourceString (readonly)

Returns:

  • (String)


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

def source
  @source
end

#urlString (readonly)

Returns:

  • (String)


8
9
10
# File 'lib/miteru/website.rb', line 8

def url
  @url
end

Instance Method Details

#defanged_truncated_urlObject



51
52
53
# File 'lib/miteru/website.rb', line 51

def defanged_truncated_url
  truncated_url.to_s.gsub(".", "[.]")
end

#index?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/miteru/website.rb', line 32

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

#infoObject



55
56
57
# File 'lib/miteru/website.rb', line 55

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

#kitsObject



28
29
30
# File 'lib/miteru/website.rb', line 28

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

#kits?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/miteru/website.rb', line 36

def kits?
  kits.any?
end


40
41
42
# File 'lib/miteru/website.rb', line 40

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

#titleObject



24
25
26
# File 'lib/miteru/website.rb', line 24

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

#truncated_urlString

Returns:

  • (String)


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

def truncated_url
  url.truncate(64)
end