pretty_table 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.9.2)
11
+ rcov (0.9.10)
12
+ rspec (2.3.0)
13
+ rspec-core (~> 2.3.0)
14
+ rspec-expectations (~> 2.3.0)
15
+ rspec-mocks (~> 2.3.0)
16
+ rspec-core (2.3.1)
17
+ rspec-expectations (2.3.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.3.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ jeweler (~> 1.6.4)
27
+ rcov
28
+ rspec (~> 2.3.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 John Wulff
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ pretty_table
2
+ ============
3
+ Turns multidimensional data into a pretty table.
4
+
5
+ Example
6
+ -------
7
+ Top 10 countries by population from the CIA World Factbook https://www.cia.gov/library/publications/the-world-factbook/rankorder/2119rank.html
8
+
9
+ This:
10
+
11
+ headers = [ 'Country', 'Population', 'Date of Information' ]
12
+ data = [ [ 'China', 1336718015, 'July 2011 est.' ],
13
+ [ 'India', 1189172906, 'July 2011 est.' ],
14
+ [ 'United States', 313232044, 'July 2011 est.' ],
15
+ [ 'Indonesia', 245613043, 'July 2011 est.' ],
16
+ [ 'Brazil', 203429773 ],
17
+ [ 'Pakistan', 187342721, 'July 2011 est.' ],
18
+ [ 'Bangladesh', 158570535, 'July 2011 est.' ],
19
+ [ 'Nigeria', 155215573 ],
20
+ [ 'Russia', 138739892, 'July 2011 est.' ],
21
+ [ 'Japan', 126475664, 'July 2011 est.' ] ]
22
+ puts PrettyTable.new(data, headers).to_s
23
+
24
+ Makes:
25
+
26
+ Country | Population | Date of Information
27
+ --------------+---------------+--------------------
28
+ China | 1,336,718,015 | July 2011 est.
29
+ India | 1,189,172,906 | July 2011 est.
30
+ United States | 313,232,044 | July 2011 est.
31
+ Indonesia | 245,613,043 | July 2011 est.
32
+ Brazil | 203,429,773 |
33
+ Pakistan | 187,342,721 | July 2011 est.
34
+ Bangladesh | 158,570,535 | July 2011 est.
35
+ Nigeria | 155,215,573 |
36
+ Russia | 138,739,892 | July 2011 est.
37
+ Japan | 126,475,664 | July 2011 est.
38
+
39
+ Contributing to pretty_table
40
+ ----------------------------
41
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
42
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
43
+ * Fork the project
44
+ * Start a feature/bugfix branch
45
+ * Commit and push until you are happy with your contribution
46
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
47
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
48
+
49
+ Copyright
50
+ ---------
51
+ Copyright (c) 2011 John Wulff. See LICENSE.txt for
52
+ further details.
53
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "pretty_table"
18
+ gem.homepage = "http://github.com/jwulff/pretty_table"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Turns multidimensional data into a pretty table.}
21
+ gem.description = %Q{Turns multidimensional data into a pretty table.}
22
+ gem.email = "johnw@orcasnet.com"
23
+ gem.authors = ["John Wulff"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "pretty_table #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,90 @@
1
+ class PrettyTable
2
+ attr_reader :data, :headers
3
+
4
+ def initialize(data = [], headers = [])
5
+ @data = data
6
+ @headers = headers
7
+ end
8
+
9
+ def to_s
10
+ string = ''
11
+ string << header_cells.join(' | ')
12
+ string << "\n"
13
+ string << divider_cells.join('-+-')
14
+ string << "\n"
15
+ data_rows.each do |data_cells|
16
+ string << data_cells.join(' | ')
17
+ string << "\n"
18
+ end
19
+ string
20
+ end
21
+
22
+ private
23
+ def data_strings
24
+ @data_strings ||= data.collect do |row|
25
+ row.collect do |cell|
26
+ if cell.is_a?(Numeric)
27
+ [ cell.to_s.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse, :rjust ]
28
+ else
29
+ [ cell.to_s, :ljust ]
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ def header_strings
36
+ @header_strings ||= headers.collect do |cell|
37
+ if cell.is_a?(Numeric)
38
+ [ cell.to_s.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse, :center ]
39
+ else
40
+ [ cell.to_s, :center ]
41
+ end
42
+ end
43
+ end
44
+
45
+ def column_sizes
46
+ unless @column_sizes
47
+ @column_sizes = []
48
+ ([header_strings] + data_strings).each do |row|
49
+ row.each_with_index do |column, index|
50
+ column_sizes[index] ||= 0
51
+ size = column[0].size
52
+ column_sizes[index] = size if size > column_sizes[index]
53
+ end
54
+ end
55
+ end
56
+ @column_sizes
57
+ end
58
+
59
+ def header_cells
60
+ column_sizes.each_with_index.collect do |size, column|
61
+ if header_strings[column]
62
+ header_strings[column][0].send header_strings[column][1], size
63
+ else
64
+ ' ' * size
65
+ end
66
+ end
67
+ end
68
+
69
+ def divider_cells
70
+ column_sizes.each_with_index.collect do |size, column|
71
+ '-' * size
72
+ end
73
+ end
74
+
75
+ def data_rows
76
+ data_strings.collect do |row|
77
+ data_cells row
78
+ end
79
+ end
80
+
81
+ def data_cells(row)
82
+ column_sizes.each_with_index.collect do |size, column|
83
+ if row[column]
84
+ row[column][0].send row[column][1], size
85
+ else
86
+ ' ' * size
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{pretty_table}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["John Wulff"]
12
+ s.date = %q{2011-09-14}
13
+ s.description = %q{Turns multidimensional data into a pretty table.}
14
+ s.email = %q{johnw@orcasnet.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/pretty_table.rb",
29
+ "pretty_table.gemspec",
30
+ "spec/pretty_table_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/jwulff/pretty_table}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.6}
37
+ s.summary = %q{Turns multidimensional data into a pretty table.}
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ else
49
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
50
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
52
+ s.add_dependency(%q<rcov>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "PrettyTable" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'pretty_table'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pretty_table
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - John Wulff
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-09-14 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ~>
24
+ - !ruby/object:Gem::Version
25
+ segments:
26
+ - 2
27
+ - 3
28
+ - 0
29
+ version: 2.3.0
30
+ requirement: *id001
31
+ name: rspec
32
+ prerelease: false
33
+ type: :development
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 1
41
+ - 0
42
+ - 0
43
+ version: 1.0.0
44
+ requirement: *id002
45
+ name: bundler
46
+ prerelease: false
47
+ type: :development
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 1
55
+ - 6
56
+ - 4
57
+ version: 1.6.4
58
+ requirement: *id003
59
+ name: jeweler
60
+ prerelease: false
61
+ type: :development
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirement: *id004
71
+ name: rcov
72
+ prerelease: false
73
+ type: :development
74
+ description: Turns multidimensional data into a pretty table.
75
+ email: johnw@orcasnet.com
76
+ executables: []
77
+
78
+ extensions: []
79
+
80
+ extra_rdoc_files:
81
+ - LICENSE.txt
82
+ - README.md
83
+ files:
84
+ - .document
85
+ - .rspec
86
+ - Gemfile
87
+ - Gemfile.lock
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - VERSION
92
+ - lib/pretty_table.rb
93
+ - pretty_table.gemspec
94
+ - spec/pretty_table_spec.rb
95
+ - spec/spec_helper.rb
96
+ has_rdoc: true
97
+ homepage: http://github.com/jwulff/pretty_table
98
+ licenses:
99
+ - MIT
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project:
122
+ rubygems_version: 1.3.6
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Turns multidimensional data into a pretty table.
126
+ test_files: []
127
+