Class: Hst::Reader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Reader

Returns a new instance of Reader.



21
22
23
# File 'lib/hst.rb', line 21

def initialize(file)
  open(file)
end

Instance Attribute Details

Returns the value of attribute copyright.



14
15
16
# File 'lib/hst.rb', line 14

def copyright
  @copyright
end

#digitsObject (readonly)

Returns the value of attribute digits.



17
18
19
# File 'lib/hst.rb', line 17

def digits
  @digits
end

#lastsyncObject (readonly)

Returns the value of attribute lastsync.



19
20
21
# File 'lib/hst.rb', line 19

def lastsync
  @lastsync
end

#periodObject (readonly)

Returns the value of attribute period.



16
17
18
# File 'lib/hst.rb', line 16

def period
  @period
end

#symbolObject (readonly)

Returns the value of attribute symbol.



15
16
17
# File 'lib/hst.rb', line 15

def symbol
  @symbol
end

#timesignObject (readonly)

Returns the value of attribute timesign.



18
19
20
# File 'lib/hst.rb', line 18

def timesign
  @timesign
end

#versionObject (readonly)

Returns the value of attribute version.



13
14
15
# File 'lib/hst.rb', line 13

def version
  @version
end

Instance Method Details

#open(file) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hst.rb', line 25

def open(file)
  @f = File.open(file, 'rb')
  e = @f.read(96).unpack('IC64C12I4')
  raise "File size too small (must be >= 96 bytes)" if e[-1].nil?
  @version = e[0]
  @packet_size, @packet_format = Hst::Format(@version)
  @copyright = e[1..64].pack('C64')
  @symbol = e[65..76].pack('C12')
  @period = e[77]
  @digits = e[78]
  @timesign = Time.at(e[79])
  @lastsync = Time.at(e[80])
  @f.read(52)
end

#readObject



40
41
42
43
44
45
46
47
# File 'lib/hst.rb', line 40

def read
  while not @f.eof do
    data = @f.read(@packet_size)
    t, o, h, l, c, v, s, rv = data.unpack(@packet_format)
    yield Time.at(t), o, h, l, c, v, s, rv
  end
  @f.close
end