formatador 0.0.4 → 0.0.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.
- data/VERSION +1 -1
- data/formatador.gemspec +3 -3
- data/lib/formatador.rb +20 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/formatador.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{formatador}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Wesley Beary"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-02-14}
|
13
13
|
s.description = %q{STDOUT text formatting}
|
14
14
|
s.email = %q{wbeary@engineyard.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/formatador.rb
CHANGED
@@ -65,6 +65,26 @@ class Formatador
|
|
65
65
|
print("\n")
|
66
66
|
end
|
67
67
|
|
68
|
+
def display_table(data)
|
69
|
+
widths = []
|
70
|
+
data.each do |row|
|
71
|
+
row.length.times do |column|
|
72
|
+
widths[column] = [(widths[column] || 0), row[column].to_s.length].max
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
display_line("+#{widths.map{|width| '-' * (width.to_s.length + 2)}.join('+')}+")
|
77
|
+
data.length.times do |row|
|
78
|
+
columns = []
|
79
|
+
widths.length.times do |column|
|
80
|
+
value = data[row][column] || ''
|
81
|
+
columns << "#{value}#{' ' * (widths[column] - value.to_s.length)}"
|
82
|
+
end
|
83
|
+
display_line("| #{columns.join(' | ')} |")
|
84
|
+
display_line("+#{widths.map{|width| '-' * (width.to_s.length + 2)}.join('+')}+")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
68
88
|
def format(string)
|
69
89
|
if STDOUT.tty?
|
70
90
|
string.gsub(FORMAT_REGEX) { "\e[#{STYLES[$1.to_sym]}m" }.gsub(INDENT_REGEX) { indentation }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formatador
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wesley Beary
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-14 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|