Class: Apullo::Target

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Target

Returns a new instance of Target.



12
13
14
# File 'lib/apullo/target.rb', line 12

def initialize(id)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/apullo/target.rb', line 10

def id
  @id
end

Instance Method Details

#domain?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/apullo/target.rb', line 49

def domain?
  return false if host.match? /[0-9]\z/

  PublicSuffix.valid?(host, default_rule: nil)
end

#hostObject



20
21
22
# File 'lib/apullo/target.rb', line 20

def host
  @host ||= uri&.host
end

#ip?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
# File 'lib/apullo/target.rb', line 42

def ip?
  IPAddr.new host
  true
rescue IPAddr::InvalidAddressError => _e
  false
end

#ipv4Object



16
17
18
# File 'lib/apullo/target.rb', line 16

def ipv4
  @ipv4 ||= resolve
end

#schemeObject



24
25
26
# File 'lib/apullo/target.rb', line 24

def scheme
  @scheme ||= uri&.scheme
end

#uriObject



32
33
34
35
36
# File 'lib/apullo/target.rb', line 32

def uri
  @uri ||= Addressable::URI.parse(_url)
rescue Addressable::URI::InvalidURIError => _e
  nil
end

#urlObject



28
29
30
# File 'lib/apullo/target.rb', line 28

def url
  @url ||= uri&.to_s
end

#valid?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/apullo/target.rb', line 38

def valid?
  uri && (ip? | domain?)
end