excel2csv 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/excel2csv.gemspec CHANGED
@@ -16,5 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
  gem.version = Excel2CSV::VERSION
18
18
 
19
- gem.add_development_dependency "rspec", "<= 2.6"
19
+ gem.add_development_dependency "rspec", ">= 2.8"
20
20
  end
@@ -1,4 +1,5 @@
1
- require "fileutils"
1
+ require 'fileutils'
2
+ require 'json'
2
3
 
3
4
  module Excel2CSV
4
5
  class Info
@@ -13,20 +14,22 @@ module Excel2CSV
13
14
  end
14
15
 
15
16
  def read
16
- Dir["#{@working_folder}/*.csv"].map do |file|
17
- name = File.basename(file)
18
- m = /(?<sheet>\d+)-(?<rows>\d+)(-of-(?<total_rows>\d+))?/.match(name)
19
- next if !m
20
- total_rows = (m[:total_rows] || m[:rows]).to_i
21
- preview_rows = m[:rows].to_i
22
- if name =~ /preview/
23
- @previews << {path: file, total_rows:total_rows, rows:preview_rows}
24
- else
25
- @sheets << {path: file, total_rows:total_rows, rows:total_rows}
26
- end
17
+ info = JSON.parse(File.read("#{@working_folder}/info.json"))
18
+ info['sheets'].each do |sheet_info|
19
+ @sheets << {
20
+ path: "#{@working_folder}/#{sheet_info['fullOutput']}",
21
+ total_rows: sheet_info['rowCount'],
22
+ rows: sheet_info['rowCount'],
23
+ title: sheet_info['title']
24
+ }
25
+
26
+ @previews << {
27
+ path: "#{@working_folder}/#{sheet_info['previewOutput']}",
28
+ total_rows: sheet_info['rowCount'],
29
+ rows: info['perSheetRowLimitForPreviews'],
30
+ title: sheet_info['title']
31
+ } if sheet_info['previewOutput']
27
32
  end
28
- @previews.sort! {|a, b| a[:path] <=> b[:path]}
29
- @sheets.sort! {|a, b| a[:path] <=> b[:path]}
30
33
  end
31
34
 
32
35
  def clean
@@ -1,3 +1,3 @@
1
1
  module Excel2CSV
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/excel2csv.jar CHANGED
Binary file
data/lib/excel2csv.rb CHANGED
@@ -3,6 +3,7 @@ require "excel2csv/info"
3
3
 
4
4
  require "csv"
5
5
  require "tmpdir"
6
+ require "json"
6
7
 
7
8
  module Excel2CSV
8
9
 
@@ -60,13 +61,20 @@ module Excel2CSV
60
61
  limit = options[:rows]
61
62
  path = File.expand_path(path)
62
63
  if path =~ /\.csv$/
64
+ json = {
65
+ 'generatePreviews' => !!limit,
66
+ 'perSheetRowLimitForPreviews' => limit,
67
+ 'sourceFile' => path.to_s,
68
+ 'targetDir' => working_folder
69
+ }
63
70
  total_rows = 0
64
71
  preview_rows = []
65
72
  opts = clean_options(options)
66
-
73
+ sheetJson = {}
74
+
75
+ full_output = "1-#{total_rows}.csv"
67
76
  # Transcode file to utf-8, count total and gen preview
68
-
69
- CSV.open("#{working_folder}/1-#{total_rows}.csv", "wb") do |csv|
77
+ CSV.open("#{working_folder}/#{full_output}", "wb") do |csv|
70
78
  CSV.foreach(path, opts) do |row|
71
79
  if limit && total_rows <= limit
72
80
  preview_rows << row
@@ -75,12 +83,20 @@ module Excel2CSV
75
83
  csv << row
76
84
  end
77
85
  end
86
+ sheetJson['fullOutput'] = full_output
87
+ sheetJson['rowCount'] = total_rows
78
88
 
79
89
  if limit
80
- CSV.open("#{working_folder}/1-#{limit}-of-#{total_rows}-preview.csv", "wb") do |csv|
90
+ preview_output = "1-#{limit}-of-#{total_rows}-preview.csv"
91
+ sheetJson['previewOutput'] = preview_output
92
+ CSV.open("#{working_folder}/#{preview_output}", "wb") do |csv|
81
93
  preview_rows.each {|row| csv << row}
82
94
  end
83
95
  end
96
+ json['sheets'] = [sheetJson]
97
+ File.open "#{working_folder}/info.json", "wb" do |f|
98
+ f.write(JSON.generate(json))
99
+ end
84
100
  else
85
101
  java_options = options[:java_options] || "-Dfile.encoding=utf8 -Xms512m -Xmx512m -XX:MaxPermSize=256m"
86
102
  rows_limit = limit ? "-r #{limit}" : ""
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel2csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,19 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-13 00:00:00.000000000 Z
12
+ date: 2012-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70182857005000 !ruby/object:Gem::Requirement
16
+ requirement: &70145909631480 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - <=
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '2.6'
21
+ version: '2.8'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70182857005000
24
+ version_requirements: *70145909631480
25
25
  description: gem for converting Excel files to csv
26
26
  email:
27
27
  - yury.korolev@gmail.com
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  requirements: []
68
68
  rubyforge_project:
69
- rubygems_version: 1.8.10
69
+ rubygems_version: 1.8.17
70
70
  signing_key:
71
71
  specification_version: 3
72
72
  summary: extract excel worksheets to csv files