formatador 0.0.5 → 0.0.6
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 +2 -2
- data/lib/formatador.rb +24 -11
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/formatador.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
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.6"
|
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{2010-02-
|
12
|
+
s.date = %q{2010-02-20}
|
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,23 +65,36 @@ class Formatador
|
|
65
65
|
print("\n")
|
66
66
|
end
|
67
67
|
|
68
|
-
def display_table(
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
def display_table(hashes, keys = nil)
|
69
|
+
headers = keys || []
|
70
|
+
widths = {}
|
71
|
+
for hash in hashes
|
72
|
+
for key, value in hash.keys
|
73
|
+
unless keys
|
74
|
+
headers << key
|
75
|
+
end
|
76
|
+
widths[key] = [key.to_s.length, widths[key] || 0, hash[key] && hash[key].length || 0].max
|
73
77
|
end
|
78
|
+
headers = headers.uniq
|
74
79
|
end
|
75
80
|
|
76
|
-
|
77
|
-
|
81
|
+
split = "+"
|
82
|
+
for header in headers
|
83
|
+
split << ('-' * (widths[header] + 2)) << '+'
|
84
|
+
end
|
85
|
+
|
86
|
+
display_line(split)
|
87
|
+
display_line("| #{headers.join(' | ')} |")
|
88
|
+
display_line(split)
|
89
|
+
|
90
|
+
for hash in hashes
|
78
91
|
columns = []
|
79
|
-
|
80
|
-
|
81
|
-
columns << "#{
|
92
|
+
for header in headers
|
93
|
+
datum = hash[header] || ''
|
94
|
+
columns << "#{datum}#{' ' * (widths[header] - datum.length)}"
|
82
95
|
end
|
83
96
|
display_line("| #{columns.join(' | ')} |")
|
84
|
-
display_line(
|
97
|
+
display_line(split)
|
85
98
|
end
|
86
99
|
end
|
87
100
|
|
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.6
|
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: 2010-02-
|
12
|
+
date: 2010-02-20 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|