formatador 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/formatador.gemspec +2 -2
  3. data/lib/formatador.rb +24 -11
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{formatador}
8
- s.version = "0.0.5"
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-14}
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 = [
@@ -65,23 +65,36 @@ 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
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
- display_line("+#{widths.map{|width| '-' * (width.to_s.length + 2)}.join('+')}+")
77
- data.length.times do |row|
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
- widths.length.times do |column|
80
- value = data[row][column] || ''
81
- columns << "#{value}#{' ' * (widths[column] - value.to_s.length)}"
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("+#{widths.map{|width| '-' * (width.to_s.length + 2)}.join('+')}+")
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.5
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-14 00:00:00 -08:00
12
+ date: 2010-02-20 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency