Class: UdooNeoRest::ValidatePin
- Defined in:
- lib/udooneorest/validators.rb
Overview
Validate the Pin parameter
value : the pin value to be validated
Instance Attribute Summary
Attributes inherited from Validate
Instance Method Summary collapse
-
#initialize(value) ⇒ ValidatePin
constructor
A new instance of ValidatePin.
-
#to_gpio ⇒ Object
Convert a PIN reference to a GPIO reference as all the commands use GPIO.
- #valid? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ ValidatePin
Returns a new instance of ValidatePin.
89 90 91 92 93 |
# File 'lib/udooneorest/validators.rb', line 89 def initialize(value) @value = value.to_i @error_message = nil valid? end |
Instance Method Details
#to_gpio ⇒ Object
Convert a PIN reference to a GPIO reference as all the commands use GPIO
108 109 110 111 |
# File 'lib/udooneorest/validators.rb', line 108 def to_gpio return nil unless valid? GPIOS[@value] end |
#valid? ⇒ Boolean
95 96 97 98 99 100 101 102 103 |
# File 'lib/udooneorest/validators.rb', line 95 def valid? if (@value > 47) || (GPIOS[@value] == 'NA') @error_message = UdooNeoRest::Base.status_error("Pin value of #{@value} is invalid. Please refer to UDOO Neo documentation.") return false end @error_message = nil true end |