Class: BetaBrite::Files::Text

Inherits:
Object
  • Object
show all
Includes:
BetaBrite::FileDSL
Defined in:
lib/betabrite/files/text.rb

Defined Under Namespace

Classes: Mode, Position

Constant Summary collapse

WRITE =
0x41.chr
READ =
0x42.chr

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BetaBrite::FileDSL

#print, #string

Constructor Details

#initialize(label = 'A', &block) ⇒ Text

Returns a new instance of Text.



70
71
72
73
74
75
76
# File 'lib/betabrite/files/text.rb', line 70

def initialize(label = 'A', &block)
  @position = Position::MIDDLE
  @label = label
  @message = nil
  @mode  = Mode::ROTATE
  instance_eval(&block) if block
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



66
67
68
# File 'lib/betabrite/files/text.rb', line 66

def label
  @label
end

#messageObject

Returns the value of attribute message.



66
67
68
# File 'lib/betabrite/files/text.rb', line 66

def message
  @message
end

#modeObject

Returns the value of attribute mode.



66
67
68
# File 'lib/betabrite/files/text.rb', line 66

def mode
  @mode
end

#positionObject

Returns the value of attribute position.



66
67
68
# File 'lib/betabrite/files/text.rb', line 66

def position
  @position
end

Instance Method Details

#checksum(string) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/betabrite/files/text.rb', line 90

def checksum(string)
  total = 0
  string.unpack('C*').each { |i|
    total += i
  }

  sprintf("%04X", total)
end

#dotsfile(label) ⇒ Object



82
83
84
# File 'lib/betabrite/files/text.rb', line 82

def dotsfile(label)
"#{BetaBrite::Device::STRING}#{label}"
end

#stringfile(label) ⇒ Object



78
79
80
# File 'lib/betabrite/files/text.rb', line 78

def stringfile(label)
"#{BetaBrite::Device::DLE}#{label}"
end

#to_sObject



86
87
88
# File 'lib/betabrite/files/text.rb', line 86

def to_s
"#{combine}#{checksum(combine)}"
end