Class: QrForge::Payloads::Phone
- Inherits:
-
Object
- Object
- QrForge::Payloads::Phone
- Defined in:
- lib/qr_forge/payloads/phone.rb
Overview
Represents a telephone payload
Instance Method Summary collapse
-
#initialize(phone_number) ⇒ Phone
constructor
A new instance of Phone.
- #to_s ⇒ Object
-
#validate! ⇒ Object
Validates that the passed phone number is in a valid format.
Constructor Details
#initialize(phone_number) ⇒ Phone
9 10 11 |
# File 'lib/qr_forge/payloads/phone.rb', line 9 def initialize(phone_number) @phone_number = phone_number end |
Instance Method Details
#to_s ⇒ Object
13 14 15 |
# File 'lib/qr_forge/payloads/phone.rb', line 13 def to_s "tel:#{@phone_number}" end |
#validate! ⇒ Object
Validates that the passed phone number is in a valid format.
26 27 28 29 30 31 |
# File 'lib/qr_forge/payloads/phone.rb', line 26 def validate! # credit: https://ihateregex.io/expr/phone/ return if @phone_number =~ /^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$/ raise PayloadValidationError, "Invalid phone number format" end |