Class: BetaBrite::TextFile

Inherits:
Object
  • Object
show all
Defined in:
lib/files/textfile.rb

Defined Under Namespace

Classes: Mode, Position

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ TextFile

Returns a new instance of TextFile.

Yields:

  • (_self)

Yield Parameters:



65
66
67
68
69
70
# File 'lib/files/textfile.rb', line 65

def initialize
  @display_position = Position::MIDDLE
  @label = "A"
  @mode  = Mode::ROTATE
  yield self if block_given?
end

Instance Attribute Details

#display_positionObject

Returns the value of attribute display_position.



63
64
65
# File 'lib/files/textfile.rb', line 63

def display_position
  @display_position
end

#labelObject

Returns the value of attribute label.



63
64
65
# File 'lib/files/textfile.rb', line 63

def label
  @label
end

#messageObject

Returns the value of attribute message.



63
64
65
# File 'lib/files/textfile.rb', line 63

def message
  @message
end

#modeObject

Returns the value of attribute mode.



63
64
65
# File 'lib/files/textfile.rb', line 63

def mode
  @mode
end

Instance Method Details

#checksum(string) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/files/textfile.rb', line 76

def checksum(string)
  total = 0
  0.upto(string.length - 1) do |i|
    total += string[i]
  end

  sprintf("%04x", total).upcase
end

#to_sObject Also known as: inspect



72
73
74
# File 'lib/files/textfile.rb', line 72

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