table_view 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/table_view/base.rb +4 -18
- data/lib/table_view/formats/array.rb +14 -0
- data/lib/table_view/formats/csv.rb +35 -0
- data/lib/table_view/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3300ffe7a8230c8e8829c3d89e29dfc1a20b3a1c168a0bf6286386ddcd910dcc
|
4
|
+
data.tar.gz: 04a7f4fa63083e8af2069f580802c777b3e2584bb78cb55995832264124db911
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efe9227370ec63a54e3e1d9d426c85c94c0a78d29ec546ec6ce98237e34974cea33b9483afabbe0f5847371027b28b3b5e0b380ba15aafb44b09b8eeacc1dffc
|
7
|
+
data.tar.gz: 17239ff091a4d52bf19f3746a835695f9f2ee7d6d7d9aa2093a4c61d3a49e2d1b4d1d96b67cd7746755e7d4dca9f7e7937ba51c3974b1a2856a65a7a342f7cab
|
data/.gitignore
CHANGED
data/lib/table_view/base.rb
CHANGED
@@ -1,25 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative "formats/array"
|
4
|
+
require_relative "formats/csv"
|
4
5
|
|
5
6
|
module TableView
|
6
7
|
class Base
|
7
|
-
|
8
|
-
|
9
|
-
array << headers
|
10
|
-
each_row do |row|
|
11
|
-
array << row
|
12
|
-
end
|
13
|
-
array
|
14
|
-
end
|
15
|
-
|
16
|
-
def write_csv(io)
|
17
|
-
csv = CSV.new(io)
|
18
|
-
csv << headers
|
19
|
-
each_row do |row|
|
20
|
-
csv << row
|
21
|
-
end
|
22
|
-
csv.close
|
23
|
-
end
|
8
|
+
include TableView::Formats::Array
|
9
|
+
include TableView::Formats::CSV
|
24
10
|
end
|
25
11
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "csv"
|
2
|
+
|
3
|
+
module TableView
|
4
|
+
module Formats
|
5
|
+
module CSV
|
6
|
+
def as_csv
|
7
|
+
StringIO.open do |io|
|
8
|
+
write_csv_to_io(io)
|
9
|
+
io.string
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def write_csv(filepath_or_io)
|
14
|
+
if filepath_or_io.is_a?(String)
|
15
|
+
File.open(filepath_or_io, "wb") do |f|
|
16
|
+
write_csv_to_io(f)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
write_csv_to_io(filepath_or_io)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def write_csv_to_io(io)
|
26
|
+
csv = ::CSV.new(io)
|
27
|
+
csv << headers
|
28
|
+
each_row do |row|
|
29
|
+
csv << row
|
30
|
+
end
|
31
|
+
csv.close
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/table_view/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Diggins
|
@@ -87,6 +87,8 @@ files:
|
|
87
87
|
- bin/setup
|
88
88
|
- lib/table_view.rb
|
89
89
|
- lib/table_view/base.rb
|
90
|
+
- lib/table_view/formats/array.rb
|
91
|
+
- lib/table_view/formats/csv.rb
|
90
92
|
- lib/table_view/version.rb
|
91
93
|
- table_view.gemspec
|
92
94
|
homepage: https://github.com/timdiggins/table_view
|