Class: Ryo::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/ryo/target.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Target

Returns a new instance of Target.



8
9
10
11
# File 'lib/ryo/target.rb', line 8

def initialize(uri)
  @uri = URI.parse(uri)
  @domain = @uri.host
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



7
8
9
# File 'lib/ryo/target.rb', line 7

def domain
  @domain
end

#uriObject (readonly)

Returns the value of attribute uri.



7
8
9
# File 'lib/ryo/target.rb', line 7

def uri
  @uri
end

Instance Method Details

#fldObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ryo/target.rb', line 13

def fld
  @fld ||= String.new.tap do |out|
    removed_tlds_domain = domain.gsub(tlds_regexp, "")
    # test.com => ["test"]
    # dev.test.com => ["dev", "test"]
    parts = removed_tlds_domain.split(".")
    if parts.length == 1 || ip?
      out << domain
    else
      idx = domain.split(".").index(parts.last)
      out << domain.split(".")[idx..-1].join(".")
    end
  end
end

#ipObject



28
29
30
31
32
33
# File 'lib/ryo/target.rb', line 28

def ip
  @ip ||= String.new.tap do |out|
    h = Plugin::DNS.new(domain).dig("A")
    out << (h.dig("Answer")&.first&.dig("data") || "N/A")
  end
end