betabrite 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,5 +1,9 @@
1
1
  = BetaBrite Changelog
2
2
 
3
+ == 0.0.2
4
+
5
+ * Added new syntax to BetaBrite::String and BetaBrite::TextFile
6
+
3
7
  == 0.0.1
4
8
 
5
9
  * First release
data/NOTES CHANGED
@@ -1,5 +1,27 @@
1
1
  = BetaBrite Release Notes
2
2
 
3
+ == 0.0.2
4
+
5
+ This release comes with new syntax for setting attributes of
6
+ BetaBrite::String and BetaBrite::TextFile. Setting attributes like color
7
+ and character set is now less cumbersome. For example, here is the old
8
+ way to set the color using constants:
9
+ s = BetaBrite::String.new("hello")
10
+ s.color = BetaBrite::String::Color::GREEN
11
+ Instead you can do this:
12
+ s = BetaBrite::String.new("hello") { |a|
13
+ a.set_color "green"
14
+ }
15
+ You can treat TextFile similarly:
16
+ s = BetaBrite::TextFile.new { |a|
17
+ a.set_mode "compressed_rotate"
18
+ a.set_position "middle"
19
+ }
20
+ These special set functions figure out what constant you want and set it
21
+ to the attribute you want. "set_mode" looks up the name passed in in the
22
+ constants stored in the Mode class, and sets it to the mode attribute.
23
+
24
+
3
25
  == 0.0.1
4
26
 
5
27
  This is the first release of the BetaBrite sign library. Please see the RDoc,
data/lib/bb_version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class BetaBrite
2
- Version = '0.0.1'
2
+ Version = '0.0.2'
3
3
  end
@@ -62,6 +62,9 @@ class BetaBrite
62
62
 
63
63
  attr_accessor :label, :display_position, :mode, :message
64
64
 
65
+ alias_method :position, :display_position
66
+ alias_method :position=, :display_position=
67
+
65
68
  def initialize
66
69
  @display_position = Position::MIDDLE
67
70
  @label = "A"
@@ -82,6 +85,24 @@ class BetaBrite
82
85
  sprintf("%04x", total).upcase
83
86
  end
84
87
 
88
+ def method_missing(sym, *args)
89
+ if args.length > 0 && sym.to_s =~ /^set_(mode|position)$/
90
+ class_name = $1
91
+
92
+ const_sym = class_name.capitalize.to_sym
93
+
94
+ klass = self.class.const_get const_sym
95
+ if klass.const_defined? args.first.upcase.to_sym
96
+ return send("#{class_name}=".to_sym,
97
+ klass.const_get(args.first.upcase.to_sym))
98
+ else
99
+ raise ArgumentError, "no constant #{args.first.upcase}", caller
100
+ end
101
+ end
102
+
103
+ super
104
+ end
105
+
85
106
  alias :inspect :to_s
86
107
 
87
108
  private
data/lib/string.rb CHANGED
@@ -61,12 +61,28 @@ class BetaBrite
61
61
  @string = string
62
62
  @color = args[:color]
63
63
  @charset = args[:charset]
64
+ yield self if block_given?
64
65
  end
65
66
 
66
67
  def to_s
67
68
  "#{0x1a.chr}#{@charset}#{0x1c.chr}#{@color}#{@string}"
68
69
  end
69
70
 
70
- #alias :to_s :format
71
+ def method_missing(sym, *args)
72
+ if args.length > 0 && sym.to_s =~ /^set_(color|charset)$/
73
+ class_name = $1
74
+
75
+ const_sym = class_name == 'color' ? :Color : :CharSet
76
+
77
+ klass = self.class.const_get const_sym
78
+ if klass.const_defined? args.first.upcase.to_sym
79
+ return send("#{class_name}=".to_sym,
80
+ klass.const_get(args.first.upcase.to_sym))
81
+ else
82
+ raise ArgumentError, "no constant #{args.first.upcase}", caller
83
+ end
84
+ end
85
+ super
86
+ end
71
87
  end
72
88
  end
data/test/tc_string.rb ADDED
@@ -0,0 +1,20 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ $:.unshift File.join(File.dirname(__FILE__), "..", "test")
3
+
4
+ require 'test/unit'
5
+ require 'betabrite'
6
+ require 'bb_override'
7
+
8
+ class StringTest < Test::Unit::TestCase
9
+ def test_const_dsl
10
+ s = BetaBrite::String.new("hello") { |a|
11
+ a.set_color "green"
12
+ a.set_charset "five_high"
13
+ }
14
+
15
+ assert_equal(BetaBrite::String::Color::GREEN, s.color)
16
+ assert_equal(BetaBrite::String::CharSet::FIVE_HIGH, s.charset)
17
+ assert_equal("hello", s.string)
18
+ end
19
+ end
20
+
@@ -0,0 +1,18 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ $:.unshift File.join(File.dirname(__FILE__), "..", "test")
3
+
4
+ require 'test/unit'
5
+ require 'betabrite'
6
+ require 'bb_override'
7
+
8
+ class TextFileTest < Test::Unit::TestCase
9
+ def test_const_dsl
10
+ tf = BetaBrite::TextFile.new { |a|
11
+ a.set_mode "roll_down"
12
+ a.set_position "middle"
13
+ }
14
+
15
+ assert_equal(BetaBrite::TextFile::Position::MIDDLE, tf.position)
16
+ assert_equal(BetaBrite::TextFile::Mode::ROLL_DOWN, tf.mode)
17
+ end
18
+ end
data/test/ts_bb.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'test/unit'
2
2
 
3
- require 'tc_many_mem.rb'
4
- require 'tc_memory.rb'
5
- require 'tc_set_string.rb'
3
+ require 'tc_many_mem'
4
+ require 'tc_memory'
5
+ require 'tc_set_string'
6
+ require 'tc_text_file'
7
+ require 'tc_string'
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: betabrite
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2006-07-09 00:00:00 -07:00
6
+ version: 0.0.2
7
+ date: 2006-09-28 00:00:00 -07:00
8
8
  summary: Provides a Ruby interface to BetaBrite LED signs
9
9
  require_paths:
10
10
  - lib
@@ -34,6 +34,8 @@ files:
34
34
  - test/tc_many_mem.rb
35
35
  - test/tc_memory.rb
36
36
  - test/tc_set_string.rb
37
+ - test/tc_string.rb
38
+ - test/tc_text_file.rb
37
39
  - test/ts_bb.rb
38
40
  - lib/bb_version.rb
39
41
  - lib/betabrite.rb