ltsv2csv 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b97109d9496d0d83f58d1c02be4b0a835b7eded
4
+ data.tar.gz: 32d1abc637115e2c191649126dc17fc535535fa6
5
+ SHA512:
6
+ metadata.gz: 99bdaff57401582d858cf9e4cde807e9939355def657f1f6e670fc17ba966c5688dcb46b6d3d1f92da156683c5b6785fbaadd1896ae107cafc06d0ac8698992e
7
+ data.tar.gz: 0d5a78b5bc30b4eec9a9451f46e58c6dbf59cabc53a7b157f7656cc33003a9cd691cac15df61e83d3181d6a788c2ee26f4f550e8d4b588efcada2931fabc2743
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ltsv2csv.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nobuhiro Nikushi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # ltsv2csv
2
+
3
+ Convert LTSV (Labeled Tab Separated Values) to CSV
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ gem install ltsv2csv
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ `ltsv2csv` is a command line tool. It converts stdin LTSV lines to stdout CSV. The first row of output become a header row of CSV.
14
+
15
+ ### Example 1
16
+
17
+ ```
18
+ $ cat input.ltsv
19
+ foo:111 bar:222 baz:333
20
+ foo:444 bar:555 baz:666
21
+ foo:777 bar:888 baz:999
22
+
23
+ $ cat input.ltsv | ltsv2csv
24
+ bar baz foo
25
+ 222 333 111
26
+ 555 666 444
27
+ 888 999 777
28
+ ```
29
+
30
+ ### Example 2
31
+
32
+ Filter columns to output by `-k` option. Multiple keys can be specified with , separator. The specified key order is reflected in column order of csv output.
33
+
34
+ ```
35
+ $ cat input.ltsv | ltsv2csv -k baz,bar
36
+ baz bar
37
+ 333 222
38
+ 666 555
39
+ 999 888
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/[my-github-username]/ltsv2csv/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/ltsv2csv ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require 'csv'
3
+ require 'optparse'
4
+
5
+ options = {}
6
+ # default value
7
+ options[:col_sep] = "\t"
8
+ OptionParser.new do |opt|
9
+ opt.on('-k [KEYS]', 'Keys to output (multiple keys separated by ,)') {|v| options[:keys] = v.split(/\s*,\s*/) }
10
+ opt.on('-c [SEPARATOR]', 'Colum separator of csv (defaut: "\t")') {|v| options[:col_sep] = v }
11
+ opt.parse!(ARGV)
12
+ end
13
+
14
+ target_keys = []
15
+ $stdin.each_with_index do |line, i|
16
+ line.chomp!
17
+ record = Hash[line.split("\t").map{|f| f.split(":", 2)}]
18
+ if i == 0
19
+ if options[:keys]
20
+ target_keys = options[:keys] & record.keys
21
+ else
22
+ target_keys = record.keys.sort
23
+ end
24
+ puts CSV.generate_line(target_keys, col_sep: options[:col_sep])
25
+ end
26
+ puts CSV.generate_line(record.values_at(*target_keys), col_sep: options[:col_sep])
27
+ end
@@ -0,0 +1,3 @@
1
+ module Ltsv2csv
2
+ VERSION = "0.1.0"
3
+ end
data/lib/ltsv2csv.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "ltsv2csv/version"
2
+
3
+ module Ltsv2csv
4
+ end
data/ltsv2csv.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ltsv2csv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ltsv2csv"
8
+ spec.version = Ltsv2csv::VERSION
9
+ spec.authors = ["Nobuhiro Nikushi"]
10
+ spec.email = ["deneb.ge@gmail.com"]
11
+
12
+ spec.summary = "LTSV (Labeled Tab Separated Values) to CSV converter"
13
+ spec.description = "ltsv2csv command converts LTSV (Labeled Tab Separated Values) to CSV"
14
+ spec.homepage = "https://github.com/niku4i/ltsv2csv"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ltsv2csv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nobuhiro Nikushi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: ltsv2csv command converts LTSV (Labeled Tab Separated Values) to CSV
42
+ email:
43
+ - deneb.ge@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/ltsv2csv
56
+ - lib/ltsv2csv.rb
57
+ - lib/ltsv2csv/version.rb
58
+ - ltsv2csv.gemspec
59
+ homepage: https://github.com/niku4i/ltsv2csv
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.5
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: LTSV (Labeled Tab Separated Values) to CSV converter
83
+ test_files: []