Class: OsCtld::History::Reader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/osctld/history.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Reader

Returns a new instance of Reader.



6
7
8
# File 'lib/osctld/history.rb', line 6

def initialize(path)
  @f = File.open(path, 'r')
end

Instance Method Details

#closeObject



10
11
12
# File 'lib/osctld/history.rb', line 10

def close
  @f.close
end

#eachObject



14
15
16
17
18
# File 'lib/osctld/history.rb', line 14

def each
  yield(parse) until @f.eof?
rescue EOFError
  # stop
end

#eof?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/osctld/history.rb', line 22

def eof?
  @f.eof?
end

#parseObject (protected)



32
33
34
# File 'lib/osctld/history.rb', line 32

def parse
  JSON.parse(@f.readline, symbolize_names: true)
end

#readObject



26
27
28
# File 'lib/osctld/history.rb', line 26

def read
  parse
end