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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 476e9d19235a9aa447fd2ef34c4674ea8973ab28f0a060f234ad995f9cd44b78
4
- data.tar.gz: ba50dcdee078e4430a3bf79054430203c82b829754a94fe1c099a56d5b59fce5
3
+ metadata.gz: 3300ffe7a8230c8e8829c3d89e29dfc1a20b3a1c168a0bf6286386ddcd910dcc
4
+ data.tar.gz: 04a7f4fa63083e8af2069f580802c777b3e2584bb78cb55995832264124db911
5
5
  SHA512:
6
- metadata.gz: 611592ed47d624624ee67598836a7a89dca3de47e5e7abea507c5c192bb2e57c44730658fdde80b3f96e6928c9484f781fda20a10222816382b7ddf141484d18
7
- data.tar.gz: fe40a86cc404326c3925ea6b3fcedca89dd6ce7686cdfa15909fbaa35bc624a777499f09169abf7aa72f8cd43225eefecec2fdbe51c7047fee817b74776ebfd0
6
+ metadata.gz: efe9227370ec63a54e3e1d9d426c85c94c0a78d29ec546ec6ce98237e34974cea33b9483afabbe0f5847371027b28b3b5e0b380ba15aafb44b09b8eeacc1dffc
7
+ data.tar.gz: 17239ff091a4d52bf19f3746a835695f9f2ee7d6d7d9aa2093a4c61d3a49e2d1b4d1d96b67cd7746755e7d4dca9f7e7937ba51c3974b1a2856a65a7a342f7cab
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
 
10
+ /spec/fixtures/**/*.got.*
10
11
  Gemfile.lock
11
12
 
12
13
  # rspec failure tracking
@@ -1,25 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "csv"
3
+ require_relative "formats/array"
4
+ require_relative "formats/csv"
4
5
 
5
6
  module TableView
6
7
  class Base
7
- def as_array
8
- array = []
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,14 @@
1
+ module TableView
2
+ module Formats
3
+ module Array
4
+ def as_array
5
+ array = []
6
+ array << headers
7
+ each_row do |row|
8
+ array << row
9
+ end
10
+ array
11
+ end
12
+ end
13
+ end
14
+ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TableView
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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.0
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