Class: Hst::Writer
- Inherits:
-
Object
- Object
- Hst::Writer
- Defined in:
- lib/hst.rb
Instance Method Summary collapse
- #create(file, version, symbol, period, digits, timesign, lastsync) {|_self| ... } ⇒ Object
-
#initialize(file, version, symbol, period = 1, digits = 5, timesign = Time.now, lastsync = Time.now, &block) ⇒ Writer
constructor
A new instance of Writer.
- #write(t, o, h, l, c, v, s = nil, rv = nil) ⇒ Object
Constructor Details
#initialize(file, version, symbol, period = 1, digits = 5, timesign = Time.now, lastsync = Time.now, &block) ⇒ Writer
Returns a new instance of Writer.
51 52 53 |
# File 'lib/hst.rb', line 51 def initialize(file, version, symbol, period = 1, digits = 5, timesign = Time.now, lastsync = Time.now, &block) create(file, version, symbol, period, digits, timesign, lastsync, &block) end |
Instance Method Details
#create(file, version, symbol, period, digits, timesign, lastsync) {|_self| ... } ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/hst.rb', line 55 def create(file, version, symbol, period, digits, timesign, lastsync, &block) @f = File.open(file, 'wb') @packet_size, @packet_format = Hst::Format(version) header = [version, 40, 67, 41, 111, 112, 121, 114, 105, 103, 104, 116, 32, 50, 48, 48, 51, 44, 32, 77, 101, 116, 97, 81, 117, 111, 116, 101, 115, 32, 83, 111, 102, 116, 119, 97, 114, 101, 32, 67, 111, 114, 112, 46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] header += symbol.unpack('C*').fill 0, symbol.length, 12 - symbol.length header += [period, digits, timesign.to_i, lastsync.to_i] + [0] * 52 @f.write header.pack('IC64C12I4C52') yield self @f.close end |
#write(t, o, h, l, c, v, s = nil, rv = nil) ⇒ Object
66 67 68 |
# File 'lib/hst.rb', line 66 def write(t, o, h, l, c, v, s = nil, rv = nil) @f.write [t.to_i, o, h, l, c, v, s, rv].pack(@packet_format) end |