Sha256: 231ee36a167a5b8d0c8c35fd911968ae3d897ff39db436f8699f1e743a87379f
Contents?: true
Size: 783 Bytes
Versions: 7
Compression:
Stored size: 783 Bytes
Contents
module RBHive class ResultSet < Array def initialize(rows, schema) @schema = schema super(rows.map {|r| @schema.coerce_row(r) }) end def column_names @schema.column_names end def column_type_map @schema.column_type_map end def to_csv(out_file=nil) to_separated_output(",", out_file) end def to_tsv(out_file=nil) to_separated_output("\t", out_file) end def as_arrays @as_arrays ||= self.map{ |r| @schema.coerce_row_to_array(r) } end private def to_separated_output(sep, out_file) rows = self.map { |r| @schema.coerce_row_to_array(r).join(sep) } sv = rows.join("\n") return sv if out_file.nil? File.open(out_file, 'w+') { |f| f << sv } end end end
Version data entries
7 entries across 7 versions & 4 rubygems