rows2cols 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 509d17eaf763230cefce4ccd3ce6244b4655f748
4
+ data.tar.gz: 048b6366aaea146611e8f5977cbac08a51e9bc56
5
+ SHA512:
6
+ metadata.gz: f65696e084c6bba642c1a5f592236f44a279e3d132db9653b0b3e0445f8009b101f3c268dac065869266f94f0dec5bfd7aac4baca32eea950519be843fb00bba
7
+ data.tar.gz: 7bde43d8b84eb7305d6a7582154ea8dcd27b19fee52ae1ca42c09535e24275713488aac816830002e5f7a3b445456f165692377d76c960d0d1753ef9355754ee
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rows2cols.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Rob Miller
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # rows2cols
2
+
3
+ rows2cols is a script for transposing rows to columns. It accepts both
4
+ files and standard input, and allows custom separators.
5
+
6
+ For example, if you want to turn:
7
+
8
+ The
9
+ quick
10
+ brown
11
+ fox
12
+ jumped
13
+ over
14
+ the
15
+ dog
16
+
17
+ Into:
18
+
19
+ The quick brown fox
20
+ jumped over the dog
21
+
22
+ You could call:
23
+
24
+ rows2cols -c 4 -s ' ' file.txt
25
+
26
+ The default separator character is a space, and the default number of
27
+ columns is four, so we could also call this as:
28
+
29
+ rows2cols file.txt
30
+
31
+ Output is printed to standard output, so rows2cols plays nicely with
32
+ text processing pipelines.
33
+
34
+ Usage: rows2cols [options] [file, file...]
35
+ -c, --columns N Number of columns (default 4)
36
+ -s, --separator CHAR Separator character between columns (default space)
37
+ -h, --help Display this help
38
+
39
+ ## Installation
40
+
41
+ $ gem install rows2cols
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( http://github.com/robmiller/rows2cols/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rows2cols ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require_relative "../lib/rows2cols"
5
+
6
+ def run(options)
7
+ rows2cols = Rows2Cols.new(
8
+ io: ARGF,
9
+ columns: options[:columns],
10
+ separator: options[:separator]
11
+ )
12
+
13
+ rows2cols.each_row do |line|
14
+ puts line
15
+ end
16
+ end
17
+
18
+ require "optparse"
19
+
20
+ options = { columns: 4, separator: " " }
21
+
22
+ OptionParser.new do |opts|
23
+ opts.banner = "Usage: rows2cols [options] [file, file...]"
24
+
25
+ opts.on("-c", "--columns N", Integer, "Number of columns (default 4)") do |columns|
26
+ options[:columns] = columns
27
+ end
28
+
29
+ opts.on("-s", "--separator CHAR", "Separator character between columns (default space)") do |separator|
30
+ options[:separator] = separator
31
+ end
32
+
33
+ opts.on("-h", "--help", "Display this help") do
34
+ puts opts
35
+ exit
36
+ end
37
+ end.parse!
38
+
39
+ run(options)
@@ -0,0 +1,3 @@
1
+ module Rows2Cols
2
+ VERSION = "1.0.0"
3
+ end
data/lib/rows2cols.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "rows2cols/version"
2
+
3
+ class Rows2Cols
4
+ include Enumerable
5
+
6
+ def initialize(io: ARGF, columns: 4, separator: " ")
7
+ @io = io
8
+ @columns = columns
9
+ @separator = separator
10
+ end
11
+
12
+ def each
13
+ @io.each_slice(@columns) do |rows|
14
+ yield rows.map(&:chomp).join(@separator)
15
+ end
16
+ end
17
+ alias :each_row :each
18
+ end
data/rows2cols.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rows2cols/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rows2cols"
8
+ spec.version = Rows2Cols::VERSION
9
+ spec.authors = ["Rob Miller"]
10
+ spec.email = ["rob@bigfish.co.uk"]
11
+ spec.summary = %q{Translate rows, on standard input or files, into columns}
12
+ spec.description = %q{A Unix utility for transposing rows of text into columns. Handles standard input and files. Plays nicely with pipelines.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rows2cols
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Miller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-30 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A Unix utility for transposing rows of text into columns. Handles standard
42
+ input and files. Plays nicely with pipelines.
43
+ email:
44
+ - rob@bigfish.co.uk
45
+ executables:
46
+ - rows2cols
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/rows2cols
56
+ - lib/rows2cols.rb
57
+ - lib/rows2cols/version.rb
58
+ - rows2cols.gemspec
59
+ homepage: ''
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.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Translate rows, on standard input or files, into columns
83
+ test_files: []
84
+ has_rdoc: