data_list_converter 0.3.4 → 0.3.5

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
  SHA1:
3
- metadata.gz: 1f782ed47348f5746c2b97038cf5b4daea0f5426
4
- data.tar.gz: 1c6e0f668c0b941a78e48eb3778e8f462d00e82b
3
+ metadata.gz: eae8b0ae00e74f0315d7d62d76ca89955f75f590
4
+ data.tar.gz: b5b44e967bc8af50a21631edda6a3d7d7f1bfe83
5
5
  SHA512:
6
- metadata.gz: b98a5eb4d9bfcaf6aa51f88b564d18d248290d9fe7faa05df0623cc7a3769c0d2641b7eedcd1ec644d9850e9edcb29c888eae2475252e538e5e74ecf04d1413a
7
- data.tar.gz: 667a130512fc88672d4d89097ac5febbcb7e124a9ed81c947b7dd4d471d07ccab8760dc1aeebd7a3568ed1e66318586e54e10d29104c291f0a3b351f7e5661d8
6
+ metadata.gz: 8ae6682e0c402fac52343277a399588a6553eb36f9044248462b07e901eb584fb0e54699d8fbc3488c57b7aa0e002d3d9ec041617d18e5982212eab5b1b4d666
7
+ data.tar.gz: 04aec6fb7b56707fcb41912883c8a8a6c524b4eda92f911b798b9ab86be6e36209e03ca78843bed31cecb8b866a90a4cb9d6285f290082d93d09e4771855e9ca
data/README.md CHANGED
@@ -94,3 +94,11 @@ DataListConverter.register_filter(:item_iterator, :limit) do |proc, options|
94
94
  }
95
95
  end
96
96
  ```
97
+
98
+
99
+ ## Todo
100
+
101
+ - register can bind method again
102
+ - better API
103
+ - better error message
104
+ - load file/save file with auto format by extname
data/changelog.md CHANGED
@@ -4,6 +4,7 @@ Refactor.
4
4
 
5
5
  - 0.3.1 sheet name should as symbol
6
6
  - 0.3.2 support xlsx cell format
7
+ - 0.3.5 add csv_raw type
7
8
 
8
9
  ## 0.2
9
10
 
@@ -19,4 +19,20 @@ class DataListConverter
19
19
  end
20
20
  options[:filename]
21
21
  end
22
+
23
+ self.register_converter(:table_iterator, :csv_raw) do |proc, options|
24
+ CSV.generate(force_quotes: true) do |csv|
25
+ proc.call do |row|
26
+ csv << row
27
+ end
28
+ end
29
+ end
30
+
31
+ self.register_converter(:csv_raw, :table_iterator) do |input, options|
32
+ lambda { |&block|
33
+ CSV.parse(input).each do |row|
34
+ block.call(row)
35
+ end
36
+ }
37
+ end
22
38
  end
@@ -1,3 +1,3 @@
1
1
  class DataListConverter
2
- VERSION = "0.3.4".freeze
2
+ VERSION = "0.3.5".freeze
3
3
  end
data/test/base_test.rb CHANGED
@@ -11,7 +11,7 @@ describe DataListConverter do
11
11
  it 'has parameters' do
12
12
  begin
13
13
  @c.convert(:item_data, :csv_file, ITEM_DATA, csv_file: {filename: "test.csv"})
14
- File.read("test.csv").strip.must_equal CSV_DATA
14
+ File.read("test.csv").must_equal CSV_DATA
15
15
  @c.convert(:csv_file, :item_data, {filename: "test.csv"}).must_equal(ITEM_DATA)
16
16
  ensure
17
17
  FileUtils.rm_f("test.csv")
data/test/testdata.rb CHANGED
@@ -9,12 +9,11 @@ TABLE_DATA = [
9
9
  ['Bob', '33']
10
10
  ]
11
11
 
12
- CSV_DATA = %{
12
+ CSV_DATA = <<-EOF
13
13
  "name","score"
14
14
  "James","12"
15
15
  "Bob","33"
16
- }.strip
17
-
16
+ EOF
18
17
 
19
18
  MULTI_SHEET_TABLE_DATA = {
20
19
  sheet1: [['name'], ['james'], ['bob']],
data/test/types_test.rb CHANGED
@@ -16,7 +16,7 @@ describe DataListConverter do
16
16
  :multi_sheet_table_data,
17
17
  :multi_sheet_item_iterator,
18
18
  :multi_sheet_table_iterator,
19
- :csv_file, :xls_file, :xlsx_file,
19
+ :csv_file, :csv_raw, :xls_file, :xlsx_file,
20
20
  :records,
21
21
  ].sort
22
22
  )
@@ -35,6 +35,8 @@ describe DataListConverter do
35
35
  begin
36
36
  @c.convert(:item_data, :csv_file, ITEM_DATA, csv_file: {filename: "test.csv"})
37
37
  @c.convert(:csv_file, :item_data, {filename: "test.csv"}).must_equal ITEM_DATA
38
+ @c.convert(:item_data, :csv_raw, ITEM_DATA).must_equal CSV_DATA
39
+ @c.convert(:csv_raw, :item_data, CSV_DATA).must_equal ITEM_DATA
38
40
  ensure
39
41
  FileUtils.rm_f("test.csv")
40
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_list_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - linjunhalida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake