Class: QrForge::Payloads::Wifi
- Inherits:
-
Object
- Object
- QrForge::Payloads::Wifi
- Defined in:
- lib/qr_forge/payloads/wifi.rb
Overview
Represents a Wi-Fi network payload
Constant Summary collapse
- VALID_ENCRYPTIONS =
%w[WEP WPA WPA2 WPA3].freeze
- NO_PASSWORD_ENCRYPTION =
"NOPASS"
Instance Method Summary collapse
-
#encryption_type ⇒ String?
Encryption type for the Wi-Fi network.
-
#hidden ⇒ String?
Indicates if the Wi-Fi network is hidden.
-
#initialize(encryption:, ssid:, password: nil, hidden: false) ⇒ Wifi
constructor
A new instance of Wifi.
-
#parts ⇒ Array<String>
Returns the parts of the Wi-Fi payload as an array.
-
#password ⇒ String?
Password for the Wi-Fi network.
-
#ssid ⇒ String
SSID of the Wi-Fi network.
- #to_s ⇒ Object
-
#validate! ⇒ Object
Validates the Wi-Fi payload data.
Constructor Details
#initialize(encryption:, ssid:, password: nil, hidden: false) ⇒ Wifi
11 12 13 14 15 16 |
# File 'lib/qr_forge/payloads/wifi.rb', line 11 def initialize(encryption:, ssid:, password: nil, hidden: false) @encryption = encryption.upcase @ssid = ssid @password = password @hidden = hidden end |
Instance Method Details
#encryption_type ⇒ String?
Encryption type for the Wi-Fi network.
21 22 23 |
# File 'lib/qr_forge/payloads/wifi.rb', line 21 def encryption_type "T:#{@encryption}" unless @encryption == NO_PASSWORD_ENCRYPTION end |
#hidden ⇒ String?
Indicates if the Wi-Fi network is hidden
42 43 44 |
# File 'lib/qr_forge/payloads/wifi.rb', line 42 def hidden "H:true" unless @hidden.nil? || @hidden == false end |
#parts ⇒ Array<String>
Returns the parts of the Wi-Fi payload as an array.
49 50 51 52 53 54 55 56 57 |
# File 'lib/qr_forge/payloads/wifi.rb', line 49 def parts parts = [] parts << ssid parts << encryption_type parts << password parts << hidden parts.compact end |
#password ⇒ String?
Password for the Wi-Fi network.
35 36 37 |
# File 'lib/qr_forge/payloads/wifi.rb', line 35 def password "P:#{escape(@password)}" if @password && @encryption != NO_PASSWORD_ENCRYPTION end |
#ssid ⇒ String
SSID of the Wi-Fi network.
28 29 30 |
# File 'lib/qr_forge/payloads/wifi.rb', line 28 def ssid "S:#{escape(@ssid)}" end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/qr_forge/payloads/wifi.rb', line 59 def to_s "WIFI:#{parts.join(";")};;" end |
#validate! ⇒ Object
Validates the Wi-Fi payload data.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/qr_forge/payloads/wifi.rb', line 67 def validate! raise PayloadValidationError, "SSID is required" if blank?(@ssid) if @encryption != NO_PASSWORD_ENCRYPTION && blank?(@password) raise PayloadValidationError, "Password is required for #{@encryption} networks" end return if VALID_ENCRYPTIONS.include?(@encryption) || @encryption == NO_PASSWORD_ENCRYPTION raise PayloadValidationError, "Invalid encryption: #{@encryption}" end |