csb 0.4.0 → 0.5.0

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: abfc516a242c529b3b1726b6846609df41e8f617a9b9ceba69ae02d7b28d4026
4
- data.tar.gz: d40c9e5d581bad2b10559b41f4935a772943c139432b7ce06837dc88ba65900f
3
+ metadata.gz: 518693b4dfa9ef958beb05143afa99c8bc37a8a61fa8b86ea5619140b4898c66
4
+ data.tar.gz: a155dc1d962466e7d0ed1421910b4dd964de3e55a79ca1092cbe63e3a82591c0
5
5
  SHA512:
6
- metadata.gz: d98d4bfa10070f589622deb111c38a90b4eedcd6df222edb7fe4eb52f807b11a3c8d1dd684f92a2c07c21929c687adb632ce65dd9aacdca3bb2a8d7b4a911447
7
- data.tar.gz: fb3283a59df41d2e0e5adcf26d260dc955d4094357aacd39320291000e84e5fb128d2b81550d5efa5e0d56587474fa8bacd118030cfd77ecfcf53f02c9f0166e
6
+ metadata.gz: 61fff01a75f9ada5135fc20b1cce96949150e4ec88d60862e373f3460f5421e04190315199892163ff9a45e6e15190ba305b315f5b8d014944b0786b27bb9698
7
+ data.tar.gz: 6cc80f9bbff9d15f844de89ca35429b529fb1054a655246de2f1cfebc55e8769d1560aa6b1f53bedeaac831901f54354fa768cc9d5879526c7fdeba3f060447d
@@ -1,3 +1,7 @@
1
+ ## 0.5.0
2
+
3
+ - Add `as_table` testing helper
4
+
1
5
  ## 0.4.0
2
6
 
3
7
  - Csb::Cols#initialize supports block arguments
data/README.md CHANGED
@@ -5,6 +5,13 @@
5
5
 
6
6
  A simple and streaming support CSV template engine for Ruby on Rails.
7
7
 
8
+ ## Features
9
+
10
+ - Support for streaming downloads
11
+ - Output in UTF-8 with BOM
12
+ - Readable code
13
+ - High testability
14
+
8
15
  ## Usage
9
16
 
10
17
  ### Template handler
@@ -21,9 +28,13 @@ In app/views/reports/index.csv.csb:
21
28
 
22
29
  ```ruby
23
30
  csv.items = @reports
31
+
24
32
  # When there are many records
25
33
  # csv.items = @reports.find_each
26
34
 
35
+ # When there are many records with decorator
36
+ # csv.items = @reports.find_each.lazy.map(&:decorate)
37
+
27
38
  # csv.filename = "reports_#{Time.current.to_i}.csv"
28
39
  # csv.streaming = false
29
40
 
@@ -68,7 +79,7 @@ csv.cols = Article.csb_cols
68
79
 
69
80
  # Your Model
70
81
  def self.csb_cols
71
- Csb.cols.new do |cols|
82
+ Csb::Cols.new do |cols|
72
83
  cols.add('Update date') { |r| I18n.l(r.updated_at.to_date) }
73
84
  cols.add('Categories') { |r| r.categories.pluck(:name).join(' ') }
74
85
  cols.add('Title', :title)
@@ -83,6 +94,12 @@ expect(Article.csb_cols.col_pairs(article)).to eq [
83
94
  ['Categories', 'test rspec'],
84
95
  ['Title', 'Testing'],
85
96
  ]
97
+
98
+ expect(Article.csb_cols.as_table(articles)).to eq [
99
+ ['Update date', 'Categories', 'Title'],
100
+ ['2020-01-01', 'test rspec', 'Testing'],
101
+ ['2020-02-01', 'rails gem', 'Rails 6.2'],
102
+ ]
86
103
  ```
87
104
 
88
105
  ## Installation
@@ -3,5 +3,9 @@ module Csb
3
3
  def col_pairs(item)
4
4
  headers.zip(values(item))
5
5
  end
6
+
7
+ def as_table(items)
8
+ [headers] + items.map { |item| values(item) }
9
+ end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module Csb
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-13 00:00:00.000000000 Z
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails