mymatrix 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ # Logfile created on 2013-03-19 10:48:19 +0900 by logger.rb/25413
@@ -0,0 +1,69 @@
1
+ = mymatrix
2
+
3
+ == DESCRIPTION:
4
+
5
+ mymatrix is a handling library for MS Excel and csv/tsv text.
6
+
7
+ == FEATURES/PROBLEMS:
8
+
9
+ Support filetypes: .xls, .tsv, .csv
10
+
11
+
12
+ == SYNOPSIS:
13
+
14
+
15
+
16
+ == REQUIREMENTS:
17
+
18
+ Support ruby versions are:
19
+ ruby 1.8.7,
20
+ ruby 1.9.2 or higher
21
+
22
+ == INSTALL:
23
+ gem install mymatrix
24
+ (It's hosted on gemcutter.org)
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2009-2013 zucay
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
+
50
+ == HOW TO USE:
51
+ ## load and wright file
52
+ ```ruby
53
+ require 'mymatrix'
54
+ mx = MyMatrix.new('path/to/xlsfile.xls')
55
+ mx.each_with_index do |row, i|
56
+ the_column = 'sample_column_name'
57
+
58
+ # print value of the cell.
59
+ p mx.val(row, the_column)
60
+
61
+ # write value of the cell
62
+ mx.setValue(row, the_column, i) # write "i" value to the cell
63
+
64
+ # text_output(default is csv)
65
+ mx.to_t('path/to/text.txt')
66
+ # csv_output
67
+ mx.to_csv('path/to/csv.csv')
68
+ end
69
+ ```
@@ -0,0 +1,69 @@
1
+ = mymatrix
2
+
3
+ == DESCRIPTION:
4
+
5
+ mymatrix is a handling library for MS Excel and csv/tsv text.
6
+
7
+ == FEATURES/PROBLEMS:
8
+
9
+ Support filetypes: .xls, .tsv, .csv
10
+
11
+
12
+ == SYNOPSIS:
13
+
14
+
15
+
16
+ == REQUIREMENTS:
17
+
18
+ Support ruby versions are:
19
+ ruby 1.8.7,
20
+ ruby 1.9.2 or higher
21
+
22
+ == INSTALL:
23
+ gem install mymatrix
24
+ (It's hosted on gemcutter.org)
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2009-2013 zucay
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
+
50
+ == HOW TO USE:
51
+ ## load and wright file
52
+ ```ruby
53
+ require 'mymatrix'
54
+ mx = MyMatrix.new('path/to/xlsfile.xls')
55
+ mx.each_with_index do |row, i|
56
+ the_column = 'sample_column_name'
57
+
58
+ # print value of the cell.
59
+ p mx.val(row, the_column)
60
+
61
+ # write value of the cell
62
+ mx.setValue(row, the_column, i) # write "i" value to the cell
63
+
64
+ # text_output(default is csv)
65
+ mx.to_t('path/to/text.txt')
66
+ # csv_output
67
+ mx.to_csv('path/to/csv.csv')
68
+ end
69
+ ```
@@ -177,14 +177,10 @@ class MyMatrix
177
177
  out.addColumn(colName, col)
178
178
  end
179
179
  return out
180
- end
181
- def val(row, str)
182
- getValue(row, str)
183
- end
184
-
185
- def getValue(row, str)
180
+ end
181
+ def getValue(row, str, offset = 0)
186
182
  out = nil
187
- index = @headerH[str]
183
+ index = @headerH[str] + offset
188
184
  if(index)
189
185
  out = row[index]
190
186
  #お尻のセルでNULLの場合などは、nilが返却されてしまう。なので、''となるようにする。
@@ -214,25 +210,23 @@ class MyMatrix
214
210
 
215
211
  =end
216
212
 
217
- def setValue(row, str, value)
213
+ def setValue(row, str, value, offset = 0)
218
214
  if(!row)
219
215
  raise 'row is nil'
220
216
  end
221
- index = @headerH[str]
222
- if(!index)
223
- addHeaders([str])
224
- end
217
+ @headerH[str] ||= addHeaders([str])
218
+ index = @headerH[str] + offset
225
219
  #参照先の値も変更できるように、破壊メソッドを使う。row[@headerH[str]] = valueでは、参照先が切り替わってしまうので、値の置き換えにならない。
226
220
  #findなどで取得したrowに対して処理を行う際に必要な変更。
227
- if(row[@headerH[str]].class == String)
228
- row[@headerH[str]].sub!(/^.*$/, value)
221
+ if(row[index].class == String)
222
+ row[index].sub!(/^.*$/, value)
229
223
  else
230
224
  #raise('not string error.')
231
225
  #todo 強烈なバグな気もするが、例外を回避し値を代入2010年12月15日
232
226
  begin
233
- row[@headerH[str]] = value.to_s
227
+ row[index] = value.to_s
234
228
  rescue
235
- row[@headerH[str]] = ''
229
+ row[index] = ''
236
230
  end
237
231
  end
238
232
  end
@@ -404,13 +398,23 @@ class MyMatrix
404
398
  fo.print("")
405
399
  else
406
400
  str = yield(row)
407
- fo.print(str)
401
+ if(str)
402
+ fo.print(str)
403
+ else
404
+ next
405
+ end
408
406
  end
409
407
  fo.print("\r\n")
410
408
  end
411
409
  fo.close
412
410
  end
413
411
  # テキスト出力する。outFileにxlsが指定された場合は、xls出力する。
412
+ # デフォルトではタブ区切りテキスト。outFileの拡張子を.csvにした場合はカンマ区切りテキスト。
413
+ # optsに設定できる値:
414
+ # :enc => 文字コード。'u':UTF-8, 's':Shift_JISのみ設定可能。デフォルトはShift_JIS(CP932)
415
+ # :separator => テキスト出力するときのセパレータ。
416
+ # :escape => エスケープするか
417
+ # :remove_empty_row => 空行を削除するか。デフォルトfalse(空行を出力する)
414
418
  def to_t(outFile=nil, opts={})
415
419
  if(!outFile)
416
420
  outFile = @file
@@ -447,9 +451,10 @@ class MyMatrix
447
451
  orow << cell.to_s.gsub(/[#{opts[:separator]}\r\n]/, '')
448
452
  end
449
453
  end
450
-
454
+
455
+ str = orow.join(opts[:separator])
451
456
  begin
452
- str = localEncode(orow.join(opts[:separator]), opts[:enc])
457
+ out_str = localEncode(str, opts[:enc])
453
458
  rescue Encoding::UndefinedConversionError
454
459
  orow.each do |ele|
455
460
  begin
@@ -461,7 +466,14 @@ class MyMatrix
461
466
 
462
467
  @log.debug(row.join(opts[:separator]))
463
468
  end
464
- str
469
+ if(opts[:remove_empty_row])
470
+ empty_str = localEncode(Array.new(row.size, '').join(opts[:separator]),opts[:enc])
471
+
472
+ if(empty_str == out_str)
473
+ out_str = nil
474
+ end
475
+ end
476
+ out_str
465
477
  end
466
478
  end
467
479
  def myescape(cell)
@@ -954,7 +966,7 @@ class MyMatrix
954
966
  self.each do |row|
955
967
  self.getHeaders.each do |head|
956
968
  val = self.val(row, head)
957
- if(val =~ /(.*)[  ]$/)
969
+ if(val =~ /(.*)[  ]+$/)
958
970
  self.setValue(row, head, $1)
959
971
  end
960
972
  end
@@ -1,3 +1,3 @@
1
1
  class MyMatrix
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -0,0 +1 @@
1
+ # Logfile created on 2012-08-30 15:40:04 +0900 by logger.rb/25413
@@ -9,7 +9,8 @@ describe MyMatrix do
9
9
  Encoding.default_external = 'Windows-31J'
10
10
  end
11
11
  end
12
-
12
+ after :all do
13
+ end
13
14
  it '4行と4行のデータをconcatFileで結合すると8行になること' do
14
15
  @mx = MyMatrix.new('spec/line4.xls')
15
16
  @mx.concatFile('spec/line4.xls')
@@ -151,6 +152,7 @@ describe MyMatrix do
151
152
  mx = MyMatrix.new('spec/out.xls')
152
153
  mx.val(mx[0], 'P-a').should == 'iti'
153
154
  mx.val(mx[0], 'P-b').should == 'foo'
155
+ File.delete('spec/out.xls')
154
156
  end
155
157
  it '同じシーケンスIDに同一の値をsetできること' do
156
158
  mx = MyMatrix.new()
@@ -292,13 +294,23 @@ describe MyMatrix do
292
294
  mx.addHeaders(['str'])
293
295
  mx << ['盌']
294
296
  Proc {
295
- mx.to_t('test.txt')
297
+ mx.to_t('spec/test.txt')
296
298
  }.should raise_error
297
299
  end
298
300
  it 'ヘッダが半角でも対応できること' do
299
301
  mx = makeHankakuSample
300
302
  mx.val(mx[0], '削除フラグ').should == '4'
301
303
  end
304
+
305
+ it 'to_tのオプション:remove_empty_row をtrueにすると、空行を出力しないこと' do
306
+ output_mx = makeEmptySample
307
+ output_mx.to_t('spec/test.txt', {:remove_empty_row => true })
308
+ fi = File.open('spec/test.txt')
309
+ fi.count.should == 2
310
+ fi.close
311
+ File.delete('spec/test.txt')
312
+ end
313
+
302
314
  end
303
315
  def translationCheck(testcases)
304
316
  mx = MyMatrix.new
@@ -315,6 +327,7 @@ def translationCheck(testcases)
315
327
  testcases.each_with_index do |mycase, i|
316
328
  mx[i][0].should == mycase[1]
317
329
  end
330
+ File.delete('spec/test.txt')
318
331
  end
319
332
 
320
333
  def makeSample
@@ -342,6 +355,7 @@ def makeEmptySample
342
355
  out << ['4', '5', '8']
343
356
  out << ['', '', '']
344
357
  out << ['', '', '']
358
+ out << ['', '', '']
345
359
  return out
346
360
  end
347
361
  def makeHankakuSample
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mymatrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-05 00:00:00.000000000 Z
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -66,92 +66,43 @@ executables: []
66
66
  extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
- - !binary |-
70
- R2VtZmlsZQ==
71
- - !binary |-
72
- UkVBRE1FLnJkb2M=
73
- - !binary |-
74
- UmFrZWZpbGU=
75
- - !binary |-
76
- bGliL2ZpbGVfaW8ucmI=
77
- - !binary |-
78
- bGliL2xvYWRlcl9jc3YucmI=
79
- - !binary |-
80
- bGliL2xvYWRlcl9mYWN0b3J5LnJi
81
- - !binary |-
82
- bGliL2xvYWRlcl90eHQucmI=
83
- - !binary |-
84
- bGliL2xvYWRlcl94bHMucmI=
85
- - !binary |-
86
- bGliL215bWF0cml4LnJi
87
- - !binary |-
88
- bGliL215bWF0cml4L3ZlcnNpb24ucmI=
89
- - !binary |-
90
- bXltYXRyaXguZ2Vtc3BlYw==
91
- - !binary |-
92
- cGtnL215bWF0cml4LTAuMC4xLmdlbQ==
93
- - !binary |-
94
- cGtnL215bWF0cml4LTAuMC4yLmdlbQ==
95
- - !binary |-
96
- cGtnL215bWF0cml4LTAuMC4zLmdlbQ==
97
- - !binary |-
98
- cGtnL215bWF0cml4LTAuMC40LmdlbQ==
99
- - !binary |-
100
- cGtnL215bWF0cml4LTAuMC41LmdlbQ==
101
- - !binary |-
102
- cGtnL215bWF0cml4LTAuMC44LmdlbQ==
103
- - !binary |-
104
- cGtnL215bWF0cml4LTAuMC45LmdlbQ==
105
- - !binary |-
106
- cGtnL215bWF0cml4LTAuMS4wLmdlbQ==
107
- - !binary |-
108
- cGtnL215bWF0cml4LTAuMS42LmdlbQ==
109
- - !binary |-
110
- c3BlYy9jc3YuY3N2
111
- - !binary |-
112
- c3BlYy9jc3YuY3N2LnR4dA==
113
- - !binary |-
114
- c3BlYy9jc3ZfdGVzdC5jc3Y=
115
- - !binary |-
116
- c3BlYy9mb3JfY29uY2F0L2NvbjEueGxz
117
- - !binary |-
118
- c3BlYy9mb3JfY29uY2F0L2NvbjIueGxz
119
- - !binary |-
120
- c3BlYy9mb3JfY29uY2F0L2NvbjMueGxz
121
- - !binary |-
122
- c3BlYy9mb3JfY29uY2F0L2NvbjQueGxz
123
- - !binary |-
124
- c3BlYy9pbmZvX2xpc3QudHh0
125
- - !binary |-
126
- c3BlYy9qcHRlc3QudHh0
127
- - !binary |-
128
- c3BlYy9saW5lNC50eHQ=
129
- - !binary |-
130
- c3BlYy9saW5lNC54bHM=
131
- - !binary |-
132
- c3BlYy9teW1hdHJpeF9zcGVjLnJi
133
- - !binary |-
134
- c3BlYy9vZmZzZXQudHh0
135
- - !binary |-
136
- c3BlYy9vdXQueGxz
137
- - !binary |-
138
- c3BlYy9zdGRfc2hvc2hpa2kueGxz
139
- - !binary |-
140
- c3BlYy90ZW1wbGF0ZS54bHM=
141
- - !binary |-
142
- c3BlYy90ZXN0LmNzdg==
143
- - !binary |-
144
- c3BlYy90ZXN0LnR4dA==
145
- - !binary |-
146
- c3BlYy90ZXN0X2hlbHBlci5yYg==
147
- - !binary |-
148
- c3BlYy90ZXN0X215bWF0cml4LnJi
149
- - !binary |-
150
- c3BlYy93b3Jkcy8wMDFfc2hlZXQuZG9j
151
- - !binary |-
152
- c3BlYy93b3Jkcy8wMDJfc2hlZXQuZG9j
153
- - !binary |-
154
- c3BlYy93b3Jkcy8wMDNfc2hlZXQuZG9j
69
+ - lib/file_io.rb
70
+ - lib/loader_csv.rb
71
+ - lib/loader_factory.rb
72
+ - lib/loader_txt.rb
73
+ - lib/loader_xls.rb
74
+ - lib/mymatrix/version.rb
75
+ - lib/mymatrix.rb
76
+ - Gemfile
77
+ - MyMatrix_ERR_0.log
78
+ - Rakefile
79
+ - README.html
80
+ - README.md
81
+ - README.rdoc
82
+ - spec/csv.csv
83
+ - spec/csv.csv.txt
84
+ - spec/csv_test.csv
85
+ - spec/for_concat/con1.xls
86
+ - spec/for_concat/con2.xls
87
+ - spec/for_concat/con3.xls
88
+ - spec/for_concat/con4.xls
89
+ - spec/info_list.txt
90
+ - spec/jptest.txt
91
+ - spec/line4.txt
92
+ - spec/line4.xls
93
+ - spec/MyMatrix_ERR_0.log
94
+ - spec/mymatrix_spec.rb
95
+ - spec/offset.txt
96
+ - spec/std_shoshiki.xls
97
+ - spec/template.xls
98
+ - spec/test.csv
99
+ - spec/test.tsv
100
+ - spec/test_helper.rb
101
+ - spec/test_mymatrix.rb
102
+ - spec/words/001_sheet.doc
103
+ - spec/words/002_sheet.doc
104
+ - spec/words/003_sheet.doc
105
+ - spec/ダクテン(だくてん)つきファイル.txt
155
106
  homepage: ''
156
107
  licenses: []
157
108
  post_install_message:
@@ -203,16 +154,12 @@ test_files:
203
154
  c3BlYy9teW1hdHJpeF9zcGVjLnJi
204
155
  - !binary |-
205
156
  c3BlYy9vZmZzZXQudHh0
206
- - !binary |-
207
- c3BlYy9vdXQueGxz
208
157
  - !binary |-
209
158
  c3BlYy9zdGRfc2hvc2hpa2kueGxz
210
159
  - !binary |-
211
160
  c3BlYy90ZW1wbGF0ZS54bHM=
212
161
  - !binary |-
213
162
  c3BlYy90ZXN0LmNzdg==
214
- - !binary |-
215
- c3BlYy90ZXN0LnR4dA==
216
163
  - !binary |-
217
164
  c3BlYy90ZXN0X2hlbHBlci5yYg==
218
165
  - !binary |-
@@ -1,26 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "mymatrix/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "mymatrix"
7
- s.version = MyMatrix::VERSION
8
- s.authors = ["yukihico"]
9
- s.email = ["yukihico@gmail.com"]
10
- s.homepage = ""
11
- s.summary = %q{MS Excel and csv/tsv text handling library}
12
- s.description = %q{mymatrix is a handling library for MS Excel and csv/tsv text.}
13
-
14
- s.rubyforge_project = "mymatrix"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- # specify any dependencies here; for example:
22
- s.add_development_dependency "rspec"
23
- s.add_dependency "exeach"
24
- s.add_dependency "spreadsheet"
25
- # s.add_runtime_dependency "rest-client"
26
- end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file