rails-exporter 0.0.13 → 0.1.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: dbf6c483c1bb4010ab215a8942027c2c114ce76f7b8fc541a4cf39871754308d
4
- data.tar.gz: 0c40e99735364d5d5073b8f1a60f59d2465940efd303a9dd42e761367d875218
3
+ metadata.gz: 7e91ed677d4f3fd9f576dd1e4330cbc8e5f8646d0a98bfde55054f345a0a9088
4
+ data.tar.gz: b45c4a7a8ff446845e70a3267fae455f564a15e751e662dc9abf5286755528ff
5
5
  SHA512:
6
- metadata.gz: 8c8bd85da0cc10ee446af85a1eac8d098246e20655f93c61eef85d0cd4c55dbbec92104920f5393f7ccccc8d9e467017ebaf1aca75641b2a67e7da2ff689c468
7
- data.tar.gz: 912658d5a451fe9620ab569381d656e3f9f0f0ce6cec3563d9689586da81139a6cefabac6ae490b8f3efebefe233f9a3f83b81a5cd7a05295499831e36af8c21
6
+ metadata.gz: ad6e274f71662e663c9b7f7174e5a9165ed2776c897f455124443c302f02abd4db2f528fd34e341c922c6963b6713c4ce6cf9cd95f5d983f92b0a7e51a548ee5
7
+ data.tar.gz: 8a3cc162e5401baf43d001e98d990fcfd88c42aa67bee68d9a4d4c114424b384ffc28d3c776dc61fc59f49385be87304a920f1a7f4a856deb7f7006b572ea483
data/README.md CHANGED
@@ -63,6 +63,9 @@ You can call `export_to` from **Array** or **ActiveRecord::Relation** objects:
63
63
  ## With context :simple
64
64
  # records.export_to(:csv, :simple)
65
65
  # or MyModelExporter.export_to_csv(records, :simple)
66
+
67
+ ## CSV Custom Params
68
+ # records.export_to(:csv, params: {col_sep: ','}))
66
69
  ```
67
70
 
68
71
  ### Avaliable Types
@@ -13,8 +13,9 @@ module RailsExporter
13
13
  end
14
14
 
15
15
  module ClassMethods
16
- def export_to_csv(records, context=:default)
17
- CSV.generate({:col_sep => ';', :force_quotes => true}) do |csv|
16
+ def export_to_csv(records, context=:default, params: {})
17
+ custom_params = {col_sep: ';', force_quotes: true}.merge(params)
18
+ CSV.generate(custom_params) do |csv|
18
19
  # HEADER
19
20
  csv << get_columns(context).map do |attr|
20
21
  attr_name(attr)
@@ -26,9 +27,10 @@ module RailsExporter
26
27
  end
27
28
  end
28
29
 
29
- def export_to_xml(records, context=:default)
30
+ def export_to_xml(records, context=:default, params: nil)
31
+ #TODO: custom params
30
32
  #File XML
31
- xml = Builder::XmlMarkup.new(:indent => 2)
33
+ xml = Builder::XmlMarkup.new(indent: 2)
32
34
  #Format
33
35
  xml.instruct! :xml, :encoding => "UTF-8"
34
36
  xml.records do
@@ -46,7 +48,8 @@ module RailsExporter
46
48
  end
47
49
  end
48
50
 
49
- def export_to_xls(records, context=:default)
51
+ def export_to_xls(records, context=:default, params: nil)
52
+ #TODO: custom params
50
53
  #FILE
51
54
  file_contents = StringIO.new
52
55
  #CHARSET
@@ -72,7 +75,8 @@ module RailsExporter
72
75
  file_contents.string.force_encoding('binary')
73
76
  end
74
77
 
75
- def export_to_xlsx(records, context=:default)
78
+ def export_to_xlsx(records, context=:default, params: nil)
79
+ #TODO: custom params
76
80
  #NEW document/spreadsheet
77
81
  workbook = RubyXL::Workbook.new
78
82
  worksheet = workbook[0]
@@ -3,20 +3,20 @@ require 'rails_exporter/base'
3
3
  module RailsExporter
4
4
  module Helper
5
5
 
6
- define_method "export_to" do |ext, context=:default|
7
- exec_method(ext, context)
6
+ define_method "export_to" do |ext, context=:default, params: nil|
7
+ exec_method(ext, context, params: params)
8
8
  end
9
9
 
10
10
  private
11
11
  def get_obj_class
12
12
  (self.first.class rescue nil)
13
13
  end
14
- def exec_method(ext, context)
14
+ def exec_method(ext, context, params: nil)
15
15
  klass = get_obj_class
16
16
  exporter_klass = "#{klass.name}_exporter".classify.constantize
17
17
  # RailsExporter::Base.file_types
18
18
  if exporter_klass and exporter_klass.respond_to?("export_to_#{ext}")
19
- exporter_klass.send("export_to_#{ext}", self, context)
19
+ exporter_klass.send("export_to_#{ext}", self, context, params: params)
20
20
  end
21
21
  end
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module RailsExporter
2
- VERSION = "0.0.13"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Porto