Sha256: 0a006158689728e224ccd0b6d2dfc1fa0e972140bceaf19f4ec1674d7c4fcd27

Contents?: true

Size: 750 Bytes

Versions: 833

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

833 entries across 833 versions & 1 rubygems

Version Path
rbbt-util-5.34.16 share/rbbt_commands/tsv/json
rbbt-util-5.34.15 share/rbbt_commands/tsv/json
rbbt-util-5.34.14 share/rbbt_commands/tsv/json
rbbt-util-5.34.13 share/rbbt_commands/tsv/json
rbbt-util-5.34.12 share/rbbt_commands/tsv/json
rbbt-util-5.34.11 share/rbbt_commands/tsv/json
rbbt-util-5.34.10 share/rbbt_commands/tsv/json
rbbt-util-5.34.9 share/rbbt_commands/tsv/json
rbbt-util-5.34.8 share/rbbt_commands/tsv/json
rbbt-util-5.34.7 share/rbbt_commands/tsv/json
rbbt-util-5.34.5 share/rbbt_commands/tsv/json
rbbt-util-5.34.4 share/rbbt_commands/tsv/json
rbbt-util-5.34.3 share/rbbt_commands/tsv/json
rbbt-util-5.34.2 share/rbbt_commands/tsv/json
rbbt-util-5.34.1 share/rbbt_commands/tsv/json
rbbt-util-5.34.0 share/rbbt_commands/tsv/json
rbbt-util-5.33.21 share/rbbt_commands/tsv/json
rbbt-util-5.33.20 share/rbbt_commands/tsv/json
rbbt-util-5.33.19 share/rbbt_commands/tsv/json
rbbt-util-5.33.18 share/rbbt_commands/tsv/json