Class: QrForge::Payloads::Url
- Inherits:
-
Object
- Object
- QrForge::Payloads::Url
- Defined in:
- lib/qr_forge/payloads/url.rb
Overview
Represents a URL payload
Instance Method Summary collapse
-
#initialize(url) ⇒ Url
constructor
A new instance of Url.
- #to_s ⇒ Object
-
#validate! ⇒ Object
Validates that the passed url is a valid HTTP or HTTPS URL.
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_s ⇒ Object
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 |