Sha256: 0a006158689728e224ccd0b6d2dfc1fa0e972140bceaf19f4ec1674d7c4fcd27

Contents?: true

Size: 750 Bytes

Versions: 835

Compression:

Stored size: 750 Bytes

Contents

#!/usr/bin/env ruby

require 'rbbt-util'
require 'rbbt/util/simpleopt'

options = SOPT.get("-tch--tokyocabinet:-tcb--tokyocabinet_bd:-m--melt:-s--snake_case")

file = ARGV.shift

case
when options[:tokyocabinet]
  tsv = Persist.open_tokyocabinet(file, false)
when options[:tokyocabinet_bd]
  tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB)
else
  tsv = TSV.open(Open.open(file))
end

fields = tsv.fields

if options[:snake_case]
 tsv.fields = fields = fields.collect{|f| Misc.snake_case f}
end

raise "No fields specified" if fields.nil?
if options[:melt]
 puts tsv.to_hash.collect{|key, values|
  h = {:key => key}
  fields.zip(values).each do |field, v|
   h[field] = v
  end
  h
 }.to_json
else
 puts tsv.to_hash.to_json
end

Version data entries

835 entries across 835 versions & 1 rubygems

Version Path
rbbt-util-5.33.19 share/rbbt_commands/tsv/json
rbbt-util-5.33.18 share/rbbt_commands/tsv/json
rbbt-util-5.33.17 share/rbbt_commands/tsv/json
rbbt-util-5.33.16 share/rbbt_commands/tsv/json
rbbt-util-5.33.15 share/rbbt_commands/tsv/json
rbbt-util-5.33.14 share/rbbt_commands/tsv/json
rbbt-util-5.33.13 share/rbbt_commands/tsv/json
rbbt-util-5.33.12 share/rbbt_commands/tsv/json
rbbt-util-5.33.11 share/rbbt_commands/tsv/json
rbbt-util-5.33.9 share/rbbt_commands/tsv/json
rbbt-util-5.33.8 share/rbbt_commands/tsv/json
rbbt-util-5.33.7 share/rbbt_commands/tsv/json
rbbt-util-5.33.6 share/rbbt_commands/tsv/json
rbbt-util-5.33.5 share/rbbt_commands/tsv/json
rbbt-util-5.33.4 share/rbbt_commands/tsv/json
rbbt-util-5.33.3 share/rbbt_commands/tsv/json
rbbt-util-5.33.2 share/rbbt_commands/tsv/json
rbbt-util-5.33.1 share/rbbt_commands/tsv/json
rbbt-util-5.33.0 share/rbbt_commands/tsv/json
rbbt-util-5.32.30 share/rbbt_commands/tsv/json