class MovingsignApi::FileHandle
Text file handle
Valid values are:
-
Integer - (0 - 35)
-
String '0' - '9', 'A' - 'Z'
Attributes
handle[RW]
@return [Integer] the file hander integer
Public Class Methods
code_to_handle(code)
click to toggle source
Returns the file handle as an integer when given a file handle string
# File lib/movingsign_api/commands/internal/file_handle.rb, line 20 def self.code_to_handle(code) if code.match /[0-9]/ code.to_i else (code.unpack('C')[0] - 'A'.unpack('C')[0]) + 10 end end
handle_to_code(handle)
click to toggle source
Returns a file handle string when given a file handle integer
# File lib/movingsign_api/commands/internal/file_handle.rb, line 29 def self.handle_to_code(handle) if handle.between?(0,9) handle.to_s else (0x41 + handle - 10).chr end end
new(input)
click to toggle source
# File lib/movingsign_api/commands/internal/file_handle.rb, line 15 def initialize(input) self.handle = self.class.parse_file_handle(input) end
Private Class Methods
parse_file_handle(input)
click to toggle source
# File lib/movingsign_api/commands/internal/file_handle.rb, line 43 def self.parse_file_handle(input) if input.kind_of?(Fixnum) && input.between?(0, 35) input elsif input.kind_of?(String) && input.match(/\A[0-9A-Z]\z/) code_to_handle(input) else raise InvalidInputError, "File handle '#{input}' is invalid." end end
Public Instance Methods
to_bytes()
click to toggle source
# File lib/movingsign_api/commands/internal/file_handle.rb, line 37 def to_bytes string_to_ascii_bytes self.class.handle_to_code(self.handle) end