Class: MovingsignApi::FileHandle
- Inherits:
-
Object
- Object
- MovingsignApi::FileHandle
- Includes:
- Utilities
- Defined in:
- lib/movingsign_api/commands/internal/file_handle.rb
Overview
Text file handle
Valid values are:
-
Integer - (0 - 35)
-
String ‘0’ - ‘9’, ‘A’ - ‘Z’
Instance Attribute Summary collapse
-
#handle ⇒ Integer
The file hander integer.
Class Method Summary collapse
-
.code_to_handle(code) ⇒ Object
Returns the file handle as an integer when given a file handle string.
-
.handle_to_code(handle) ⇒ Object
Returns a file handle string when given a file handle integer.
Instance Method Summary collapse
-
#initialize(input) ⇒ FileHandle
constructor
A new instance of FileHandle.
- #to_bytes ⇒ Object
Constructor Details
#initialize(input) ⇒ FileHandle
Returns a new instance of FileHandle.
15 16 17 |
# File 'lib/movingsign_api/commands/internal/file_handle.rb', line 15 def initialize(input) self.handle = self.class.parse_file_handle(input) end |
Instance Attribute Details
#handle ⇒ Integer
Returns the file hander integer.
13 14 15 |
# File 'lib/movingsign_api/commands/internal/file_handle.rb', line 13 def handle @handle end |
Class Method Details
.code_to_handle(code) ⇒ Object
Returns the file handle as an integer when given a file handle string
20 21 22 23 24 25 26 |
# 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) ⇒ Object
Returns a file handle string when given a file handle integer
29 30 31 32 33 34 35 |
# 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 |
Instance Method Details
#to_bytes ⇒ Object
37 38 39 |
# 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 |