list_to_columns 1.0.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: 017461bbc767b91781b3f5ba696ddcaa069a882a
4
+ data.tar.gz: 3240eefbcf3b3e7a9de6bf3dc4a759fd28d1b8e7
5
+ SHA512:
6
+ metadata.gz: ae59d2bc3fd23d8a8034a560dc87c67b12d9ff49fa3181cd579af3a506cfdf7b6768e696c2b33298b4d2a0af6adb49b339e6d51afc5db82f89790605b56f7911
7
+ data.tar.gz: c6b80de38eaf82bd0963f27a30a57852bfd90dc0829df94dec4321905cc82666bc4d8f07406089c3b6e4cf52ca1fe2474e5e90fc6e8e6d682079d26a23dc626d
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Style/MultilineOperationIndentation:
2
+ EnforcedStyle: indented
data/.semver ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :major: 1
3
+ :minor: 0
4
+ :patch: 0
5
+ :special: ''
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - '2.0'
4
+ - '2.1'
5
+ - '2.2'
6
+ script:
7
+ - bundle exec rake build
8
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in list_to_columns.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Christian Höltje
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,82 @@
1
+ [![Build
2
+ Status](https://travis-ci.org/docwhat/list_to_columns.svg)](https://travis-ci.org/docwhat/list_to_columns)
3
+ [![Coverage
4
+ Status](https://coveralls.io/repos/docwhat/list_to_columns/badge.svg?branch=master&service=github)](https://coveralls.io/github/docwhat/list_to_columns?branch=master)
5
+ [![Dependency
6
+ Status](https://gemnasium.com/docwhat/list_to_columns.svg)](https://gemnasium.com/docwhat/list_to_columns)
7
+
8
+ ListToColumns
9
+ =============
10
+
11
+ Have a list of strings but want to display it in a compact column format?
12
+ `ListToColumns` is the tool for the job!
13
+
14
+ It turns boring lists like:
15
+
16
+ Dedanim signally eyebright unpebbled ureterolithic boyishly auriculares cynebot evaluation literatus
17
+
18
+ or:
19
+
20
+ * Haidan
21
+ * Soleidae
22
+ * paleoanthropological
23
+ * Peba
24
+ * biaxillary
25
+ * preultimate
26
+ * convivialist
27
+ * amphistome
28
+ * shoaly
29
+ * cornloft
30
+
31
+ ...into glorious multi-columnar lists:
32
+
33
+ conventual uranospinite scallom
34
+ enantiopathia biserially Bogomil
35
+ scyphozoan Addisonian mislayer
36
+
37
+ Installation
38
+ ------------
39
+
40
+ Add this line to your application's Gemfile:
41
+
42
+ ``` ruby
43
+ gem 'list_to_columns'
44
+ ```
45
+
46
+ And then execute:
47
+
48
+ $ bundle
49
+
50
+ Or install it yourself as:
51
+
52
+ $ gem install list_to_columns
53
+
54
+ Usage
55
+ -----
56
+
57
+ TODO: Write usage instructions here
58
+
59
+ Development
60
+ -----------
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
63
+ `rake rspec` to run the tests. You can also run `bin/console` for an
64
+ interactive prompt that will allow you to experiment.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To
67
+ release a new version, update the version number in `version.rb`, and then run
68
+ `bundle exec rake release`, which will create a git tag for the version, push
69
+ git commits and tags, and push the `.gem` file to
70
+ [rubygems.org](https://rubygems.org).
71
+
72
+ Contributing
73
+ ------------
74
+
75
+ Bug reports and pull requests are welcome on GitHub at
76
+ https://github.com/docwhat/list\_to\_columns.
77
+
78
+ License
79
+ -------
80
+
81
+ The gem is available as open source under the terms of the [MIT
82
+ License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+
6
+ task default: :test
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ RuboCop::RakeTask.new(:style)
10
+
11
+ # building should depend on the tests passing.
12
+ task build: [:test]
13
+
14
+ # Test task
15
+ desc 'Runs all the tests'
16
+ task test: [:spec, :style]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'list_to_columns'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ require 'list_to_columns/version'
2
+ require 'list_to_columns/column_major'
3
+
4
+ # Allow Arrays to be displayed as columnar lists instead.
5
+ module ListToColumns
6
+ def self.new(*args)
7
+ ColumnMajor.new(*args)
8
+ end
9
+ end
@@ -0,0 +1,55 @@
1
+ module ListToColumns
2
+ # Columnar list that is column major order; that is the order is
3
+ # top->bottom, then right->left.
4
+ class ColumnMajor
5
+ attr_reader :width, :space
6
+
7
+ def initialize(list = nil, options = nil)
8
+ options ||= {}
9
+ @width = options[:width] || 78
10
+ @space = options[:space] || 2
11
+ @strings = Array(list).map(&:to_s)
12
+ return if @strings.empty?
13
+
14
+ # Pad out list so it is rectangular.
15
+ @strings[number_of_columns * number_of_rows - 1] ||= nil
16
+ end
17
+
18
+ def longest_string_length
19
+ @longest_string_length ||= @strings.map(&:length).max || 0
20
+ end
21
+
22
+ def number_of_columns
23
+ return 0 if @strings.empty?
24
+ @number_of_columns ||= (width + space) / (longest_string_length + space)
25
+ end
26
+
27
+ def number_of_rows
28
+ return 0 if @strings.empty?
29
+ @number_of_rows ||= (@strings.length.to_f / number_of_columns).ceil
30
+ end
31
+
32
+ def matrix
33
+ @matrix ||= @strings
34
+ .each_slice(number_of_rows)
35
+ .to_a
36
+ .transpose
37
+ .map(&:compact)
38
+ .map(&:freeze)
39
+ .freeze
40
+ end
41
+
42
+ def to_s
43
+ matrix
44
+ .map { |r| r.map { |s| pad s }.join(' ' * space) }
45
+ .map(&:rstrip)
46
+ .join("\n")
47
+ end
48
+
49
+ private
50
+
51
+ def pad(string)
52
+ format "%-#{longest_string_length}s", string
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,13 @@
1
+ require 'yaml'
2
+
3
+ # Monkey patch the version number.
4
+ module ListToColumns
5
+ VERSION ||= begin
6
+ semver = YAML.load(
7
+ File.read(
8
+ File.expand_path('../../../.semver', __FILE__)
9
+ )
10
+ )
11
+ [semver[:major], semver[:minor], semver[:patch]].join('.')
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'list_to_columns/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'list_to_columns'
8
+ spec.version = ListToColumns::VERSION
9
+ spec.authors = ['Christian Höltje']
10
+ spec.email = ['docwhat@gerf.org']
11
+
12
+ spec.summary = 'Formats a list into columns'
13
+ spec.description = 'Given an Array of Strings, it formats it into '\
14
+ 'columns to make it more compact for terminal displays.'
15
+ spec.homepage = 'https://github.com/docwhat/list_to_columns'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`
19
+ .split("\x0")
20
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.10'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'psych'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'rspec-given'
30
+ spec.add_development_dependency 'rubocop'
31
+ spec.add_development_dependency 'simplecov'
32
+ spec.add_development_dependency 'coveralls'
33
+ spec.add_development_dependency 'semver2', '~> 3.4'
34
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: list_to_columns
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Höltje
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-20 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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
+ - !ruby/object:Gem::Dependency
42
+ name: psych
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-given
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: semver2
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.4'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.4'
139
+ description: Given an Array of Strings, it formats it into columns to make it more
140
+ compact for terminal displays.
141
+ email:
142
+ - docwhat@gerf.org
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".semver"
151
+ - ".travis.yml"
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
158
+ - lib/list_to_columns.rb
159
+ - lib/list_to_columns/column_major.rb
160
+ - lib/list_to_columns/version.rb
161
+ - list_to_columns.gemspec
162
+ homepage: https://github.com/docwhat/list_to_columns
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.4.8
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: Formats a list into columns
186
+ test_files: []