Class: BetaBrite
- Inherits:
-
Object
- Object
- BetaBrite
- Defined in:
- lib/betabrite.rb,
lib/string.rb,
lib/bb_version.rb,
lib/memory/memory.rb,
lib/files/dotsfile.rb,
lib/files/textfile.rb,
lib/files/stringfile.rb
Overview
Synopsis
This class assembles all packets (different files) and yields the data that needs to be written back to the caller of the BetaBrite#write method.
Defined Under Namespace
Classes: DotsFile, Memory, String, StringFile, TextFile
Constant Summary collapse
- HEADER =
[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ]
- STX =
0x02.chr
- ETX =
0x03.chr
- EOT =
0x04.chr
- ESC =
0x1b.chr
- DLE =
0x10.chr
- STRING =
0x14.chr
- CR =
0x0d.chr
- MEMORY_CODE =
"E$"
- SIGN_TYPE =
Beta Brite sign
0x5a.chr
- Version =
'0.0.1'
Instance Attribute Summary collapse
-
#dots_files ⇒ Object
readonly
Returns the value of attribute dots_files.
-
#sleep_time ⇒ Object
readonly
Returns the value of attribute sleep_time.
-
#string_files ⇒ Object
readonly
Returns the value of attribute string_files.
-
#text_files ⇒ Object
readonly
Returns the value of attribute text_files.
Instance Method Summary collapse
- #add(packet) ⇒ Object
- #add_dotsfile(packet) ⇒ Object
- #add_memory(packet) ⇒ Object
- #add_stringfile(packet) ⇒ Object
- #add_textfile(packet) ⇒ Object
-
#allocate(&block) ⇒ Object
This method is used to allocate memory on the sign.
- #header ⇒ Object
-
#initialize ⇒ BetaBrite
constructor
A new instance of BetaBrite.
- #inspect ⇒ Object
-
#write(&block) ⇒ Object
This method is used to write on the sign.
- #write_dots(&block) ⇒ Object
Constructor Details
#initialize ⇒ BetaBrite
Returns a new instance of BetaBrite.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/betabrite.rb', line 28 def initialize # Default address is "00" which means broadcast to all signs @sign_address = [ 0x30, 0x30 ] @string_files = [] @text_files = [] @dots_files = [] @memory = [] # This shouldn't change except for unit testing @sleep_time = 1 end |
Instance Attribute Details
#dots_files ⇒ Object (readonly)
Returns the value of attribute dots_files.
26 27 28 |
# File 'lib/betabrite.rb', line 26 def dots_files @dots_files end |
#sleep_time ⇒ Object (readonly)
Returns the value of attribute sleep_time.
25 26 27 |
# File 'lib/betabrite.rb', line 25 def sleep_time @sleep_time end |
#string_files ⇒ Object (readonly)
Returns the value of attribute string_files.
26 27 28 |
# File 'lib/betabrite.rb', line 26 def string_files @string_files end |
#text_files ⇒ Object (readonly)
Returns the value of attribute text_files.
26 27 28 |
# File 'lib/betabrite.rb', line 26 def text_files @text_files end |
Instance Method Details
#add(packet) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/betabrite.rb', line 49 def add(packet) if packet.is_a? BetaBrite::Memory add_memory packet elsif packet.is_a? BetaBrite::StringFile add_stringfile packet elsif packet.is_a? BetaBrite::TextFile add_textfile packet elsif packet.is_a? BetaBrite::DotsFile add_dotsfile packet end end |
#add_dotsfile(packet) ⇒ Object
69 70 71 |
# File 'lib/betabrite.rb', line 69 def add_dotsfile(packet) @dots_files << packet end |
#add_memory(packet) ⇒ Object
73 74 75 |
# File 'lib/betabrite.rb', line 73 def add_memory(packet) @memory << packet end |
#add_stringfile(packet) ⇒ Object
61 62 63 |
# File 'lib/betabrite.rb', line 61 def add_stringfile(packet) @string_files << packet end |
#add_textfile(packet) ⇒ Object
65 66 67 |
# File 'lib/betabrite.rb', line 65 def add_textfile(packet) @text_files << packet end |
#allocate(&block) ⇒ Object
This method is used to allocate memory on the sign
99 100 101 102 103 104 105 106 107 |
# File 'lib/betabrite.rb', line 99 def allocate(&block) if @memory.length > 0 write_header &block yield STX yield MEMORY_CODE @memory.each { |packet| yield packet.to_s } write_end &block end end |
#header ⇒ Object
40 41 42 43 |
# File 'lib/betabrite.rb', line 40 def header header_str = HEADER.collect { |a| a.chr }.join header_str << SIGN_TYPE << @sign_address.collect { |a| a.chr }.join end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/betabrite.rb', line 45 def inspect header end |
#write(&block) ⇒ Object
This method is used to write on the sign
78 79 80 81 82 83 84 85 |
# File 'lib/betabrite.rb', line 78 def write(&block) if @text_files.length > 0 || @string_files.length > 0 write_header &block @text_files.each { |packet| yield packet.to_s } @string_files.each { |packet| block.call(packet.to_s) } write_end &block end end |
#write_dots(&block) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/betabrite.rb', line 87 def write_dots(&block) if @dots_files.length > 0 write_header &block @dots_files.each { |packet| yield packet.to_s sleep sleep_time } write_end &block end end |