Module: Rapid::Services::CodeTable

Included in:
DummyCodeTable, Baps::Codes
Defined in:
lib/ury_rapid/services/code_table.rb

Overview

Helper module for modules representing playout system command codes

Instance Method Summary collapse

Instance Method Details

#code_symbol(code) ⇒ String

Given a code, return a vaguely descriptive textual description

This is mainly intended for debugging and logging purposes, and is wholly inadequate for user-facing code. You have been warned!

Examples:

Find the name of a command code.

# Assuming Rapid::Baps::Codes includes CodeTable,
Rapid::Baps::Codes.code_symbol(Rapid::Baps::Codes::Playback::PLAY)
#=> "Rapid::Baps::Codes::Playback::PLAY"

Parameters:

  • code (Integer)

    A code in the code table.

Returns:

  • (String)

    The (semi) human-readable name for the code.


20
21
22
23
24
25
26
27
28
29
# File 'lib/ury_rapid/services/code_table.rb', line 20

def code_symbol(code)
  # Assume that the only constants defined in Codes are code groups...
  submodules = constants.map(&method(:const_get))
  # ...and the only constants defined in code groups are codes, and they
  # are disjoint.
  found = nil
  submodules.each { |s| found = find_code_in(s, code) unless found }
  fail("Unknown code number: #{code.to_s(16)}") unless found
  found
end