Class: OsCtld::History::Reader
- Inherits:
-
Object
- Object
- OsCtld::History::Reader
- Includes:
- Enumerable
- Defined in:
- lib/osctld/history.rb
Instance Method Summary collapse
- #close ⇒ Object
- #each ⇒ Object
- #eof? ⇒ Boolean
-
#initialize(path) ⇒ Reader
constructor
A new instance of Reader.
- #parse ⇒ Object protected
- #read ⇒ Object
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
#close ⇒ Object
10 11 12 |
# File 'lib/osctld/history.rb', line 10 def close @f.close end |
#each ⇒ Object
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
22 23 24 |
# File 'lib/osctld/history.rb', line 22 def eof? @f.eof? end |
#parse ⇒ Object (protected)
32 33 34 |
# File 'lib/osctld/history.rb', line 32 def parse JSON.parse(@f.readline, symbolize_names: true) end |
#read ⇒ Object
26 27 28 |
# File 'lib/osctld/history.rb', line 26 def read parse end |