Class: LWAC::JSONFormatter

Inherits:
KeyValueFormatter show all
Defined in:
lib/lwac/export/format.rb

Overview


Output to a single JSON file

Instance Method Summary collapse

Methods inherited from KeyValueFormatter

#add_data, #initialize, #open_point

Methods inherited from Formatter

#<<, #add_data, #initialize, #open_point

Constructor Details

This class inherits a constructor from LWAC::KeyValueFormatter

Instance Method Details

#close_outputObject



96
97
98
99
# File 'lib/lwac/export/format.rb', line 96

def close_output()
  $log.info "Closing output CSV..."
  @f.close
end

#close_pointObject



107
108
109
110
111
112
# File 'lib/lwac/export/format.rb', line 107

def close_point()
  super
  @f.write(JSON.generate(@line.values))
  @f.write("\n")
  @f.flush
end

#open_outputObject

TODO: - sync after every write

- use formatter system]


91
92
93
94
# File 'lib/lwac/export/format.rb', line 91

def open_output()
  $log.info "Opening #{@config[:filename]} for writing..."
  @f = File.open( @config[:filename], 'w' )
end

#write_headerObject



101
102
103
104
105
# File 'lib/lwac/export/format.rb', line 101

def write_header
  $log.info "Writing header"
  @f.write( @config[:fields].keys )
  @f.flush
end