Class: BetaBrite::String
- Inherits:
-
Object
- Object
- BetaBrite::String
- Defined in:
- lib/betabrite/string.rb
Overview
This class encapsulates a string and attributes about the string such as color, character set, and also contains special characters.
Defined Under Namespace
Constant Summary collapse
- UP_ARROW =
0xc4.chr
- DOWN_ARROW =
0xc5.chr
- LEFT_ARROW =
0xc6.chr
- RIGHT_ARROW =
0xc7.chr
- PACKMAN =
0xc8.chr
- SAIL_BOAT =
0xc9.chr
- BALL =
0xca.chr
- TELEPHONE =
0xcb.chr
- HEART =
0xcc.chr
- CAR =
0xcd.chr
- HANDICAP =
0xce.chr
- RHINO =
0xcf.chr
- MUG =
0xd0.chr
- SATELLITE_DISH =
0xd1.chr
- COPYRIGHT =
0xd2.chr
- MALE_SYM =
0xd3.chr
- FEMALE_SYM =
0xd4.chr
- BOTTLE =
0xd5.chr
- DISKETTE =
0xd6.chr
- PRINTER =
0xd7.chr
- NOTE =
0xd8.chr
- INFINITY =
0xd9.chr
- RETURN_ARROW =
0xda.chr
- SM_UP_ARROW =
0xdb.chr
- SM_DOWN_ARROW =
0xdc.chr
- SM_LEFT_ARROW =
0xdd.chr
- SM_RIGHT_ARROW =
0xde.chr
Instance Attribute Summary collapse
-
#charset ⇒ Object
Returns the value of attribute charset.
-
#color ⇒ Object
Returns the value of attribute color.
-
#string ⇒ Object
Returns the value of attribute string.
Class Method Summary collapse
-
.parse(string) ⇒ Object
Break up a string into betabrite strings.
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#initialize(string, opts = {}) {|_self| ... } ⇒ String
constructor
A new instance of String.
- #rgb(rgb_color) ⇒ Object
- #to_s ⇒ Object (also: #to_str)
Constructor Details
#initialize(string, opts = {}) {|_self| ... } ⇒ String
Returns a new instance of String.
76 77 78 79 80 81 82 83 84 |
# File 'lib/betabrite/string.rb', line 76 def initialize(string, opts = {}) args = { :color => Color::GREEN, :charset => CharSet::SEVEN_HIGH }.merge opts @string = string @color = args[:color] @charset = args[:charset] yield self if block_given? end |
Instance Attribute Details
#charset ⇒ Object
Returns the value of attribute charset.
62 63 64 |
# File 'lib/betabrite/string.rb', line 62 def charset @charset end |
#color ⇒ Object
Returns the value of attribute color.
62 63 64 |
# File 'lib/betabrite/string.rb', line 62 def color @color end |
#string ⇒ Object
Returns the value of attribute string.
62 63 64 |
# File 'lib/betabrite/string.rb', line 62 def string @string end |
Class Method Details
.parse(string) ⇒ Object
Break up a string into betabrite strings
66 67 68 69 70 71 72 73 |
# File 'lib/betabrite/string.rb', line 66 def parse(string) string.split(/#{0x1a.chr}/).select { |s| s.length > 0 }.map { |s| data = /(.)#{0x1c.chr}Z?([^Z]{6}|[^Z])(.*)$/.match(s) new(data[3], :color => data[2], :charset => data[1]) } end |
Instance Method Details
#+(other) ⇒ Object
86 87 88 |
# File 'lib/betabrite/string.rb', line 86 def +(other) self.to_s + other.to_s end |
#rgb(rgb_color) ⇒ Object
90 91 92 93 |
# File 'lib/betabrite/string.rb', line 90 def rgb(rgb_color) self.color = "#{rgb_color}" self end |
#to_s ⇒ Object Also known as: to_str
95 96 97 98 99 |
# File 'lib/betabrite/string.rb', line 95 def to_s "#{0x1a.chr}#{@charset}#{0x1c.chr}" + (@color.length > 1 ? "Z#{@color}" : "#{@color}") + "#{@string}" end |