Class: LoGspot::Output::File

Inherits:
Object
  • Object
show all
Defined in:
lib/lo_gspot/output/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ File

Returns a new instance of File.



2
3
4
5
6
7
8
9
10
11
# File 'lib/lo_gspot/output/file.rb', line 2

def initialize(arg)
  if arg.is_a?(String)
    @physical = true
    FileUtils.mkdir_p(File.dirname(arg))
    @file = File.open(arg, 'a')
  else
    @physical = false
    @file = arg
  end
end

Instance Method Details

#finalizeObject



23
24
25
# File 'lib/lo_gspot/output/file.rb', line 23

def finalize
  file.close if physical
end

#puts(data) ⇒ Object



13
14
15
16
# File 'lib/lo_gspot/output/file.rb', line 13

def puts(data)
  file.puts(data[:message])
  file.flush
end

#write(message) ⇒ Object



18
19
20
21
# File 'lib/lo_gspot/output/file.rb', line 18

def write(message)
  file.write(message)
  file.flush
end