Class: Hst::Reader
- Inherits:
-
Object
- Object
- Hst::Reader
- Defined in:
- lib/hst.rb
Instance Attribute Summary collapse
-
#copyright ⇒ Object
readonly
Returns the value of attribute copyright.
-
#digits ⇒ Object
readonly
Returns the value of attribute digits.
-
#lastsync ⇒ Object
readonly
Returns the value of attribute lastsync.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
-
#timesign ⇒ Object
readonly
Returns the value of attribute timesign.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(file) ⇒ Reader
constructor
A new instance of Reader.
- #open(file) ⇒ Object
- #read ⇒ Object
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
#copyright ⇒ Object (readonly)
Returns the value of attribute copyright.
14 15 16 |
# File 'lib/hst.rb', line 14 def copyright @copyright end |
#digits ⇒ Object (readonly)
Returns the value of attribute digits.
17 18 19 |
# File 'lib/hst.rb', line 17 def digits @digits end |
#lastsync ⇒ Object (readonly)
Returns the value of attribute lastsync.
19 20 21 |
# File 'lib/hst.rb', line 19 def lastsync @lastsync end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
16 17 18 |
# File 'lib/hst.rb', line 16 def period @period end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
15 16 17 |
# File 'lib/hst.rb', line 15 def symbol @symbol end |
#timesign ⇒ Object (readonly)
Returns the value of attribute timesign.
18 19 20 |
# File 'lib/hst.rb', line 18 def timesign @timesign end |
#version ⇒ Object (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 |
#read ⇒ Object
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 |