-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing misstatement in README, adding csv-to-terminal-table recipe in…
… the examples dir and README
- Loading branch information
1 parent
37f13c1
commit 4bb0a7e
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
First Name,Last Name,Email | ||
TJ,Holowaychuk,tj@vision-media.ca | ||
Bob,Someone,bob@vision-media.ca | ||
Joe,Whatever,joe@vision-media.ca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "csv" | ||
$LOAD_PATH << "#{__dir__}/../lib" | ||
require "terminal-table" | ||
|
||
# | ||
# Usage: | ||
# ./show_csv_table.rb data.csv | ||
# cat data.csv | ./show_csv_table.rb | ||
# cat data.csv | ./show_csv_table.rb - | ||
# | ||
# | ||
# Reads a CSV from $stdin if no argument given, or argument is '-' | ||
# otherwise interprets first cmdline argument as the CSV filename | ||
# | ||
use_stdin = ARGV[0].nil? || (ARGV[0] == '-') | ||
io_object = use_stdin ? $stdin : File.open(ARGV[0], 'r') | ||
csv = CSV.new(io_object) | ||
|
||
# | ||
# Convert to an array for use w/ terminal-table | ||
# The assumption is that this is a pretty small spreadsheet. | ||
# | ||
csv_array = csv.to_a | ||
|
||
user_table = Terminal::Table.new do |v| | ||
v.style = { :border => :unicode_round } # >= v3.0.0 | ||
v.title = "Some Title" | ||
v.headings = csv_array[0] | ||
v.rows = csv_array[1..-1] | ||
end | ||
|
||
puts user_table |