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.43.0 share/rbbt_commands/tsv/json
rbbt-util-5.42.0 share/rbbt_commands/tsv/json
rbbt-util-5.41.1 share/rbbt_commands/tsv/json
rbbt-util-5.41.0 share/rbbt_commands/tsv/json
rbbt-util-5.40.5 share/rbbt_commands/tsv/json
rbbt-util-5.40.4 share/rbbt_commands/tsv/json
rbbt-util-5.40.3 share/rbbt_commands/tsv/json
rbbt-util-5.40.0 share/rbbt_commands/tsv/json
rbbt-util-5.39.0 share/rbbt_commands/tsv/json
rbbt-util-5.38.1 share/rbbt_commands/tsv/json
rbbt-util-5.38.0 share/rbbt_commands/tsv/json
rbbt-util-5.37.16 share/rbbt_commands/tsv/json
rbbt-util-5.37.15 share/rbbt_commands/tsv/json
rbbt-util-5.37.14 share/rbbt_commands/tsv/json
rbbt-util-5.37.13 share/rbbt_commands/tsv/json
rbbt-util-5.37.12 share/rbbt_commands/tsv/json
rbbt-util-5.37.11 share/rbbt_commands/tsv/json
rbbt-util-5.37.10 share/rbbt_commands/tsv/json
rbbt-util-5.37.9 share/rbbt_commands/tsv/json
rbbt-util-5.37.8 share/rbbt_commands/tsv/json