scrollysign 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/scrollysign.rb +12 -10
  2. metadata +3 -3
@@ -1,6 +1,8 @@
1
1
  require 'serialport'
2
2
 
3
3
  class ScrollySign
4
+ PortClosedError = Class.new(StandardError)
5
+
4
6
  class TextBuilder
5
7
  def initialize
6
8
  @text = ""
@@ -130,23 +132,23 @@ class ScrollySign
130
132
  "right" => '2'
131
133
  }
132
134
 
135
+ attr_reader :port
136
+ attr_accessor :type_code, :sign_address
133
137
 
134
138
  def initialize(port, baud_rate = 9600)
135
139
  @type_code = "Z" # all types of sign
136
140
  @sign_address = "00" # all signs
137
141
 
138
142
  @port = SerialPort.new(port, baud_rate)
139
- if block_given?
140
- begin
141
- yield self
142
- ensure
143
- close
144
- end
145
- end
146
143
  end
147
144
 
148
- def port
149
- @port
145
+ def self.open(port, baud_rate = 9600)
146
+ sign = new(port, baud_rate)
147
+ begin
148
+ yield sign
149
+ ensure
150
+ sign.close
151
+ end
150
152
  end
151
153
 
152
154
  def close
@@ -183,7 +185,7 @@ class ScrollySign
183
185
  end
184
186
 
185
187
  def write_raw(command, data)
186
- raise "port is closed" unless port
188
+ raise PortClosedError, "port is closed" unless port
187
189
 
188
190
  command_code = COMMANDS.fetch(command)
189
191
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrollysign
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Roger Nesbitt