csb 0.3.1 → 0.4.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: 3037dfb042638fd3c0ed0e186b48bdcd0a36224e0b786f4f04f948c294c61bcf
4
- data.tar.gz: f93eeb95cfd751cf0c8df6aaf43479f1c3201aad49f979df1cd3f44bd480b9d6
3
+ metadata.gz: abfc516a242c529b3b1726b6846609df41e8f617a9b9ceba69ae02d7b28d4026
4
+ data.tar.gz: d40c9e5d581bad2b10559b41f4935a772943c139432b7ce06837dc88ba65900f
5
5
  SHA512:
6
- metadata.gz: 9fb5514caecd51087c07e5ef4cb2af9134f7049b8f9d5a00d3a691577a689e6f18e856cb45302b285f2bb197aaa432f0f55d24e640b3e8278533acee701e2a4c
7
- data.tar.gz: 956abb986cc239759b16576638072bc55612ed6806c47bf65273fc507c1513405df95bc7fb26239f646979c434a73559133ce72aeacef2758e7cfdcf64007ba5
6
+ metadata.gz: d98d4bfa10070f589622deb111c38a90b4eedcd6df222edb7fe4eb52f807b11a3c8d1dd684f92a2c07c21929c687adb632ce65dd9aacdca3bb2a8d7b4a911447
7
+ data.tar.gz: fb3283a59df41d2e0e5adcf26d260dc955d4094357aacd39320291000e84e5fb128d2b81550d5efa5e0d56587474fa8bacd118030cfd77ecfcf53f02c9f0166e
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  Gemfile.lock
13
+ /vendor/bundle
@@ -1,3 +1,8 @@
1
+ ## 0.4.0
2
+
3
+ - Csb::Cols#initialize supports block arguments
4
+ - Add Testing Helper
5
+
1
6
  ## 0.3.1
2
7
 
3
8
  - Refactor
data/README.md CHANGED
@@ -59,6 +59,32 @@ csv.build
59
59
  # 2019/06/02,category3,content2,,dummy
60
60
  ```
61
61
 
62
+ ### Testing
63
+
64
+ ```ruby
65
+ # Your view
66
+ csv.items = @articles
67
+ csv.cols = Article.csb_cols
68
+
69
+ # Your Model
70
+ def self.csb_cols
71
+ Csb.cols.new do |cols|
72
+ cols.add('Update date') { |r| I18n.l(r.updated_at.to_date) }
73
+ cols.add('Categories') { |r| r.categories.pluck(:name).join(' ') }
74
+ cols.add('Title', :title)
75
+ end
76
+ end
77
+
78
+ # Your test
79
+ require 'csb/testing'
80
+
81
+ expect(Article.csb_cols.col_pairs(article)).to eq [
82
+ ['Update date', '2020-01-01'],
83
+ ['Categories', 'test rspec'],
84
+ ['Title', 'Testing'],
85
+ ]
86
+ ```
87
+
62
88
  ## Installation
63
89
 
64
90
  Add this line to your application's Gemfile:
@@ -9,6 +9,7 @@ module Csb
9
9
 
10
10
  def initialize
11
11
  @cols = []
12
+ yield(self) if block_given?
12
13
  end
13
14
 
14
15
  def copy!(other)
@@ -32,5 +33,6 @@ module Csb
32
33
  col.value_by_item(item)
33
34
  end
34
35
  end
36
+ alias_method :values, :values_by_item
35
37
  end
36
38
  end
@@ -1,7 +1,6 @@
1
1
  module Csb
2
2
  class Template
3
- attr_accessor :utf8_bom, :filename, :streaming, :items
4
- attr_reader :cols
3
+ attr_accessor :utf8_bom, :filename, :streaming, :items, :cols
5
4
 
6
5
  def initialize(utf8_bom:, streaming:)
7
6
  @utf8_bom = utf8_bom
@@ -0,0 +1,7 @@
1
+ module Csb
2
+ class Cols
3
+ def col_pairs(item)
4
+ headers.zip(values(item))
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Csb
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.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.3.1
4
+ version: 0.4.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-01 00:00:00.000000000 Z
11
+ date: 2020-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -110,6 +110,7 @@ files:
110
110
  - lib/csb/handler.rb
111
111
  - lib/csb/railtie.rb
112
112
  - lib/csb/template.rb
113
+ - lib/csb/testing.rb
113
114
  - lib/csb/version.rb
114
115
  homepage: https://github.com/aki77/csb
115
116
  licenses: