Class: UdooNeoRest::ValidatePin

Inherits:
Validate
  • Object
show all
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

#error_message, #value

Instance Method Summary collapse

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_gpioObject

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

Returns:

  • (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