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



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

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

Instance Method Details

#closeObject



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

def close
  @f.close
end

#eachObject



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

def each
  yield(parse) until @f.eof?

rescue EOFError
end

#eof?Boolean

Returns:

  • (Boolean)


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

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



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

def read
  parse
end