Class: StatusFile

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

Overview

status = StatusFile.new ‘/tmp/status’ status.send “Initialized on: #Time.now” status.send “Working… #(1.(1..100)(1..100).to_a(1..100).to_a.shuffle(1..100).to_a.shuffle.first%” status.update

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ StatusFile

Returns a new instance of StatusFile.



8
9
10
11
# File 'lib/status_file.rb', line 8

def initialize(file_path)
  @file_path = file_path
  @contents = []
end

Instance Method Details

#readObject



25
26
27
# File 'lib/status_file.rb', line 25

def read
  File.read(@file_path)
end

#send(data) ⇒ Object



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

def send data
  @contents << data
end

#updateObject



17
18
19
20
21
22
23
# File 'lib/status_file.rb', line 17

def update
  File.open(@file_path, 'w+') do |file|
    @contents.each do |line|
      file.puts line
    end
  end
end