Class: MovingsignApi::FileHandle

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

Class Method Summary collapse

Instance Method Summary collapse

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

#handleInteger

Returns the file hander integer.

Returns:

  • (Integer)

    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_bytesObject



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