Class: Apullo::Target
- Inherits:
-
Object
- Object
- Apullo::Target
- Defined in:
- lib/apullo/target.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #domain? ⇒ Boolean
- #host ⇒ Object
-
#initialize(id) ⇒ Target
constructor
A new instance of Target.
- #ip? ⇒ Boolean
- #ipv4 ⇒ Object
- #scheme ⇒ Object
- #uri ⇒ Object
- #url ⇒ Object
- #valid? ⇒ Boolean
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
#id ⇒ Object (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
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 |
#host ⇒ Object
20 21 22 |
# File 'lib/apullo/target.rb', line 20 def host @host ||= uri&.host end |
#ip? ⇒ 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 |
#ipv4 ⇒ Object
16 17 18 |
# File 'lib/apullo/target.rb', line 16 def ipv4 @ipv4 ||= resolve end |
#scheme ⇒ Object
24 25 26 |
# File 'lib/apullo/target.rb', line 24 def scheme @scheme ||= uri&.scheme end |
#uri ⇒ Object
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 |
#url ⇒ Object
28 29 30 |
# File 'lib/apullo/target.rb', line 28 def url @url ||= uri&.to_s end |
#valid? ⇒ Boolean
38 39 40 |
# File 'lib/apullo/target.rb', line 38 def valid? uri && (ip? | domain?) end |