Class: QrForge::Payloads::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/qr_forge/payloads/url.rb

Overview

Represents a URL payload

Examples:

return “example.com” or “example.com


Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Url

Returns a new instance of Url.



11
12
13
# File 'lib/qr_forge/payloads/url.rb', line 11

def initialize(url)
  @url = url
end

Instance Method Details

#to_sObject



15
16
17
# File 'lib/qr_forge/payloads/url.rb', line 15

def to_s
  @url
end

#validate!Object

Validates that the passed url is a valid HTTP or HTTPS URL.



21
22
23
24
25
26
27
28
29
# File 'lib/qr_forge/payloads/url.rb', line 21

def validate!
  uri = URI.parse(@url)

  unless uri.is_a?(::URI::HTTP) || uri.is_a?(::URI::HTTPS)
    raise PayloadValidationError, "Must be a valid HTTP/HTTPS URL"
  end
rescue ::URI::InvalidURIError
  raise PayloadValidationError, "Invalid URL syntax"
end