tablelize 0.1.5
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 +7 -0
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Rakefile +6 -0
- data/Readme.md +28 -0
- data/bin/tablelize +27 -0
- data/lib/tablelize.rb +44 -0
- data/tablelize.gemspec +22 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7f88f24b58e3cff8465522e0f4f685dcc65c7916d2c9daa220dcaefffaf313f2
|
4
|
+
data.tar.gz: c06778b2308685cd5db0176a68eb7be90f089a30eba41defb43912468436e1b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5287e135b03b3b381bdb74ff27542fabf5b8134d2eb262defbfbf93c1cd9cd1ae159e4ee2aa0d71c8c57f31b47298fa127a2125cf40f13b9fa13ed355ae880b9
|
7
|
+
data.tar.gz: 1dc5af2d327d08ea2f8f125ca22db716ee9ff86b1d7269331afa771eebfc451516e50828501be7b8ba0ef01e801e40b8fef828c70673922d7d96aed63cc9ab0c
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/
|
data/Gemfile
ADDED
data/Rakefile
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# tablelize
|
2
|
+
|
3
|
+
Tables data.
|
4
|
+
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Code:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
require "tablelize"
|
12
|
+
|
13
|
+
rows = []
|
14
|
+
rows << ["KEY", "VALUE"]
|
15
|
+
rows << ["name", "tablelize"]
|
16
|
+
rows << ["version", Tablelize::VERSION]
|
17
|
+
rows << ["some very long text", "Still looks ok"]
|
18
|
+
Tablelize::table rows
|
19
|
+
```
|
20
|
+
|
21
|
+
Result:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
KEY VALUE
|
25
|
+
name tablelize
|
26
|
+
version 0.1.0
|
27
|
+
some very long text Still looks ok
|
28
|
+
```
|
data/bin/tablelize
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + "/../lib"
|
4
|
+
|
5
|
+
require "thor"
|
6
|
+
require "tablelize"
|
7
|
+
|
8
|
+
module Tablelize
|
9
|
+
class Cli < Thor
|
10
|
+
desc "version", "Show the current version"
|
11
|
+
def version
|
12
|
+
puts VERSION
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "example", "Shows an example"
|
16
|
+
def example
|
17
|
+
rows = [["KEY", "VALUE", "NUMBER", "ALMOST_A_NUMBER"]]
|
18
|
+
rows << ["name", "tablelize", 1, 2]
|
19
|
+
rows << ["version", Tablelize::VERSION, 1.2, 3]
|
20
|
+
rows << ["π", "10 digits of pie", 3.1415926535, 3]
|
21
|
+
rows << ["some very long text", "Fake moose", 3.14, "3a"]
|
22
|
+
Tablelize::table rows
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Tablelize::Cli.start(ARGV)
|
data/lib/tablelize.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Tablelize
|
2
|
+
|
3
|
+
VERSION = "0.1.5"
|
4
|
+
SEPARATOR = ENV.fetch("TABLELIZE_SEPARATOR", " ")
|
5
|
+
HEADER_LINE = ENV.fetch("TABLELIZE_HEADER_LINE", "")
|
6
|
+
ALIGN_STRING = 1
|
7
|
+
ALIGN_NUMBER = 2
|
8
|
+
|
9
|
+
def self.table(rows)
|
10
|
+
aligns = []
|
11
|
+
widths = []
|
12
|
+
rows.each_with_index do |row, line|
|
13
|
+
row.each_with_index do |val, index|
|
14
|
+
len = val.to_s.length
|
15
|
+
widths[index] = len if widths[index].nil? || len > widths[index]
|
16
|
+
|
17
|
+
if line > 0 and aligns[index] != ALIGN_STRING
|
18
|
+
if val.is_a? Numeric
|
19
|
+
aligns[index] = ALIGN_NUMBER
|
20
|
+
else
|
21
|
+
aligns[index] = ALIGN_STRING
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
format = ""
|
29
|
+
length = 0
|
30
|
+
widths.each_with_index do |width, index|
|
31
|
+
align = (aligns[index] == ALIGN_NUMBER) ? "" : "-"
|
32
|
+
format = "#{format}%#{align}#{width}s#{SEPARATOR}"
|
33
|
+
length += width
|
34
|
+
end
|
35
|
+
|
36
|
+
rows.each_with_index do |row, index|
|
37
|
+
printf format.chomp(SEPARATOR) + "\n", *row
|
38
|
+
if index == 0 and HEADER_LINE.length > 0
|
39
|
+
puts HEADER_LINE * (length -1 + SEPARATOR.size * (rows.size - 1))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/tablelize.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require "tablelize"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tablelize"
|
8
|
+
spec.version = Tablelize::VERSION
|
9
|
+
spec.summary = "Tables your data."
|
10
|
+
spec.description = "Tables your data"
|
11
|
+
spec.homepage = "https://github.com/ptdorf/tablelize"
|
12
|
+
spec.authors = ["ptdorf"]
|
13
|
+
spec.email = ["ptdorf@gmail.com"]
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split $/
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "thor"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tablelize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ptdorf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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: Tables your data
|
42
|
+
email:
|
43
|
+
- ptdorf@gmail.com
|
44
|
+
executables:
|
45
|
+
- tablelize
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- Rakefile
|
52
|
+
- Readme.md
|
53
|
+
- bin/tablelize
|
54
|
+
- lib/tablelize.rb
|
55
|
+
- tablelize.gemspec
|
56
|
+
homepage: https://github.com/ptdorf/tablelize
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.0.3
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Tables your data.
|
79
|
+
test_files: []
|