xls_to_csv-paperclip-processor 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+ gem 'paperclip', '>=2.5.0'
3
+
4
+ group :development do
5
+ gem "bundler"
6
+ gem "jeweler", "~> 1.6.4"
7
+ end
data/README.md CHANGED
@@ -4,7 +4,7 @@ This gem is Paperclip processor, that uses xls2csv to convert .xls to .csv.
4
4
 
5
5
  ## Requirements ##
6
6
 
7
- * [Paperclip][0] ~> 2.3
7
+ * [Paperclip][0] ~> 2.5
8
8
  * [xls2csv][2]
9
9
 
10
10
  ## Installation ##
@@ -24,10 +24,9 @@ Various linux distributions should use similar methods with their respected pack
24
24
  Use it as you would any other Paperclip processor. In your model:
25
25
 
26
26
  class SomeCsvAttachement < ActiveRecord::Base
27
- before_post_process :is_xls?
28
27
  has_attached_file :data,
29
28
  :styles => {
30
- :csv => {
29
+ :converted => {
31
30
  :format => "csv",
32
31
  :params => "-c, -q 3"
33
32
  }
@@ -35,19 +34,10 @@ Use it as you would any other Paperclip processor. In your model:
35
34
  :path => ":rails_root/data/some_csv_attachements/:id_partition/:basename.:extension",
36
35
  :processors => [:xls_to_csv]
37
36
 
38
- validates_attachment_content_type :data, :content_type => ['text/csv','text/comma-separated-values','text/csv','application/csv','application/excel','application/vnd.ms-excel','application/vnd.msexcel','text/anytext','text/plain']
39
-
40
- def is_xls?
41
- [
42
- 'application/excel',
43
- 'application/vnd.ms-excel',
44
- 'application/vnd.msexcel'
45
- ].include?(self.data_content_type)
46
- end
47
-
37
+ validates_attachment_content_type :data, :content_type => ['text/csv','text/comma-separated-values','text/csv','application/csv','application/excel','application/vnd.ms-excel','application/vnd.msexcel','text/anytext','text/plain']
48
38
  end
49
39
 
50
- which will convert your .xls document into .csv, and keep both files (.xls and .csv) on the server. If your attachment is not a .xls it won't do anything.
40
+ which will convert your .xls document into .csv, and keep both files (.xls and .csv) on the server. If your attachment is not a .xls it will just copy it.
51
41
 
52
42
 
53
43
  [0]: https://github.com/thoughtbot/paperclip
data/Rakefile CHANGED
@@ -1,48 +1,36 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ # encoding: utf-8
3
2
 
3
+ require 'rubygems'
4
+ require 'bundler'
4
5
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
8
- gem.name = "xls_to_csv-paperclip-processor"
9
- gem.homepage = "http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor"
10
- gem.license = "MIT"
11
- gem.summary = %Q{Gem for easy convertation .xls to .csv with Paperclip}
12
- gem.description = %Q{If you want to convert .xls to .csv simply and unwittingly, then this gem is for you!}
13
- gem.email = "igor.alexandrov@gmail.com"
14
- gem.authors = ["Igor Alexandrov"]
15
- gem.add_dependency 'paperclip', '>=2.3.0'
16
- gem.add_development_dependency "rspec", ">= 0"
17
- gem.add_development_dependency "yard", ">= 0"
18
- end
19
- Jeweler::RubygemsDotOrgTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
- end
23
-
24
-
25
- require 'spec/rake/spectask'
26
- Spec::Rake::SpecTask.new(:spec) do |spec|
27
- spec.libs << 'lib' << 'spec'
28
- spec.spec_files = FileList['spec/**/*_spec.rb']
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
29
11
  end
12
+ require 'rake'
30
13
 
31
- Spec::Rake::SpecTask.new(:rcov) do |spec|
32
- spec.libs << 'lib' << 'spec'
33
- spec.pattern = 'spec/**/*_spec.rb'
34
- spec.rcov = true
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = 'xls_to_csv-paperclip-processor'
18
+ gem.homepage = 'http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor'
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Gem for easy convertation .xls to .csv with Paperclip}
21
+ gem.description = %Q{If you want to convert .xls to .csv simply and unwittingly, then this gem is for you!}
22
+ gem.email = "igor.alexandrov@gmail.com"
23
+ gem.authors = ["Igor Alexandrov"]
24
+ # dependencies defined in Gemfile
35
25
  end
26
+ Jeweler::RubygemsDotOrgTasks.new
36
27
 
37
- task :spec => :check_dependencies
28
+ require 'rake/rdoctask'
29
+ Rake::RDocTask.new do |rdoc|
30
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
38
31
 
39
- task :default => :spec
40
-
41
- begin
42
- require 'yard'
43
- YARD::Rake::YardocTask.new
44
- rescue LoadError
45
- task :yardoc do
46
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
47
- end
32
+ rdoc.rdoc_dir = 'rdoc'
33
+ rdoc.title = "xls_to_csv-paperclip-processor #{version}"
34
+ rdoc.rdoc_files.include('README*')
35
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
36
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -1,35 +1,46 @@
1
1
  require 'paperclip'
2
- module Paperclip
3
- class XlsToCsv < Processor
4
- attr_accessor :file, :params, :format
5
-
6
- def initialize file, options = {}, attachment = nil
7
- super
8
- @file = file
9
- @params = options[:params]
10
- @current_format = File.extname(@file.path)
11
- @basename = File.basename(@file.path, @current_format)
12
- @format = options[:format]
2
+ class Paperclip::XlsToCsv < Paperclip::Processor
3
+ attr_accessor :file, :params, :format
4
+
5
+ def initialize(file, options = {}, attachment = nil)
6
+ super
7
+
8
+ @file = file
9
+ @params = options[:params]
10
+ @current_format = File.extname(@file.path)
11
+ @basename = File.basename(@file.path, @current_format)
12
+ @format = options[:format]
13
+ end
14
+
15
+ def make
16
+ src = @file
17
+ dst = Tempfile.new([@basename, @format ? "#{@format}" : 'csv'].compact.join("."))
18
+
19
+ begin
20
+ Paperclip.run(self.command, self.parameters, :source => File.expand_path(src.path),:dest => File.expand_path(dst.path))
21
+ rescue StandardError => e
22
+ raise Paperclip::StandardError, "There was an error converting #{@basename} to csv: #{e.message}"
13
23
  end
14
24
 
15
- def make
16
- src = @file
17
- dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
18
- begin
19
- parameters = []
20
- parameters << @params
21
- parameters << ":source"
22
- parameters << "> :dest"
23
-
24
- parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
25
-
26
-
27
- system("touch #{dst.path}")
28
- success = Paperclip.run("xls2csv", parameters, :source => File.expand_path(src.path),:dest => File.expand_path(dst.path))
29
- rescue PaperclipCommandLineError => e
30
- raise PaperclipError, "There was an error converting #{@basename} to csv: #{e.message}"
31
- end
32
- return dst
25
+ return dst
26
+ end
27
+
28
+ protected
29
+
30
+ def command
31
+ @current_format == '.xls' ? 'xls2csv' : 'cp'
32
+ end
33
+
34
+ def parameters
35
+ p = []
36
+
37
+ if self.command == 'xls2csv'
38
+ p << [@params, ":source", "> :dest"]
39
+ else
40
+ p << [":source", ":dest"]
33
41
  end
42
+
43
+ p.flatten.compact.join(" ").strip.squeeze(" ")
34
44
  end
45
+
35
46
  end
@@ -4,46 +4,47 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{xls_to_csv-paperclip-processor}
8
- s.version = "0.1.1"
7
+ s.name = "xls_to_csv-paperclip-processor"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Igor Alexandrov"]
12
- s.date = %q{2011-05-21}
13
- s.description = %q{If you want to convert .xls to .csv simply and unwittingly, then this gem is for you!}
14
- s.email = %q{igor.alexandrov@gmail.com}
12
+ s.date = "2012-07-13"
13
+ s.description = "If you want to convert .xls to .csv simply and unwittingly, then this gem is for you!"
14
+ s.email = "igor.alexandrov@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "README.md"
17
17
  ]
18
18
  s.files = [
19
+ "Gemfile",
19
20
  "README.md",
20
21
  "Rakefile",
21
22
  "VERSION",
22
23
  "lib/xls_to_csv-paperclip-processor.rb",
23
24
  "xls_to_csv-paperclip-processor.gemspec"
24
25
  ]
25
- s.homepage = %q{http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor}
26
+ s.homepage = "http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor"
26
27
  s.licenses = ["MIT"]
27
28
  s.require_paths = ["lib"]
28
- s.rubygems_version = %q{1.5.2}
29
- s.summary = %q{Gem for easy convertation .xls to .csv with Paperclip}
29
+ s.rubygems_version = "1.8.15"
30
+ s.summary = "Gem for easy convertation .xls to .csv with Paperclip"
30
31
 
31
32
  if s.respond_to? :specification_version then
32
33
  s.specification_version = 3
33
34
 
34
35
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
35
- s.add_runtime_dependency(%q<paperclip>, [">= 2.3.0"])
36
- s.add_development_dependency(%q<rspec>, [">= 0"])
37
- s.add_development_dependency(%q<yard>, [">= 0"])
36
+ s.add_runtime_dependency(%q<paperclip>, [">= 2.5.0"])
37
+ s.add_development_dependency(%q<bundler>, [">= 0"])
38
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
38
39
  else
39
- s.add_dependency(%q<paperclip>, [">= 2.3.0"])
40
- s.add_dependency(%q<rspec>, [">= 0"])
41
- s.add_dependency(%q<yard>, [">= 0"])
40
+ s.add_dependency(%q<paperclip>, [">= 2.5.0"])
41
+ s.add_dependency(%q<bundler>, [">= 0"])
42
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
42
43
  end
43
44
  else
44
- s.add_dependency(%q<paperclip>, [">= 2.3.0"])
45
- s.add_dependency(%q<rspec>, [">= 0"])
46
- s.add_dependency(%q<yard>, [">= 0"])
45
+ s.add_dependency(%q<paperclip>, [">= 2.5.0"])
46
+ s.add_dependency(%q<bundler>, [">= 0"])
47
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
47
48
  end
48
49
  end
49
50
 
metadata CHANGED
@@ -1,114 +1,89 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: xls_to_csv-paperclip-processor
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Igor Alexandrov
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-21 00:00:00 +04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: paperclip
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70298183709460 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 2
32
- - 3
33
- - 0
34
- version: 2.3.0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.5.0
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70298183709460
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &70298183744220 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
49
33
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: yard
53
34
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70298183744220
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &70298183742320 !ruby/object:Gem::Requirement
55
39
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.6.4
63
44
  type: :development
64
- version_requirements: *id003
65
- description: If you want to convert .xls to .csv simply and unwittingly, then this gem is for you!
45
+ prerelease: false
46
+ version_requirements: *70298183742320
47
+ description: If you want to convert .xls to .csv simply and unwittingly, then this
48
+ gem is for you!
66
49
  email: igor.alexandrov@gmail.com
67
50
  executables: []
68
-
69
51
  extensions: []
70
-
71
- extra_rdoc_files:
52
+ extra_rdoc_files:
72
53
  - README.md
73
- files:
54
+ files:
55
+ - Gemfile
74
56
  - README.md
75
57
  - Rakefile
76
58
  - VERSION
77
59
  - lib/xls_to_csv-paperclip-processor.rb
78
60
  - xls_to_csv-paperclip-processor.gemspec
79
- has_rdoc: true
80
61
  homepage: http://github.com/igor-alexandrov/xls_to_csv-paperclip-processor
81
- licenses:
62
+ licenses:
82
63
  - MIT
83
64
  post_install_message:
84
65
  rdoc_options: []
85
-
86
- require_paths:
66
+ require_paths:
87
67
  - lib
88
- required_ruby_version: !ruby/object:Gem::Requirement
68
+ required_ruby_version: !ruby/object:Gem::Requirement
89
69
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- hash: 3
94
- segments:
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ segments:
95
75
  - 0
96
- version: "0"
97
- required_rubygems_version: !ruby/object:Gem::Requirement
76
+ hash: -3794122404308807782
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
78
  none: false
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- hash: 3
103
- segments:
104
- - 0
105
- version: "0"
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
106
83
  requirements: []
107
-
108
84
  rubyforge_project:
109
- rubygems_version: 1.5.2
85
+ rubygems_version: 1.8.15
110
86
  signing_key:
111
87
  specification_version: 3
112
88
  summary: Gem for easy convertation .xls to .csv with Paperclip
113
89
  test_files: []
114
-