xlsxtream_rails 0.4.0 → 0.6.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: 5502fc92614bd2379b7af762136ac5d37621264a14a8c95dd0c1675c06f8f8c1
4
- data.tar.gz: cf4eb50326cf589174c1dc941392a12f054d5142c48d2293b210100f37551403
3
+ metadata.gz: fb7b7fd3f2a753ee4d340d45f2ef418657be92a6608aed395974626351cf2b57
4
+ data.tar.gz: 7f7024c814a6009ebbc6a397bc6ad74cebe3631a670f7971e77df369df0bcb47
5
5
  SHA512:
6
- metadata.gz: 1171bb419c8a365726ed516eb46f53ef6a658462ad1a810629ecec67fb69c040afcbe0c6d41adf785edf7da33161bb41cfd10008d163d5c79ed5ce783c89a81f
7
- data.tar.gz: 70566d1a3ff138d3840a343e6e6a6218fd13636764784a87656149856d702f3aa34d48ad5a409221c2ec9da0297adcdc974f09ae5c88abe65601e86269526e58
6
+ metadata.gz: 9b91045886b6a4e51e3c384b0fd81e95a709180a6c14b12932c8911b4896bb5bf35208dbbc990a7c8b6a5a8ef13951cd6bc3702f03b47754cff0a25d676ed663
7
+ data.tar.gz: d314332d9e79b0af2158848dc7a31160272836c7f09af3e95cf08b8fb3645bd4ef9a29af3c7b4e28da97ba32c0d2e348b79ce3f3d7c4193ac48916ac803c9c5d
@@ -12,7 +12,7 @@ ActionController::Renderers.add :xlsx do |data, options|
12
12
  options[:filename] ||= if defined?(ActiveRecord) && data.is_a?(ActiveRecord::Relation)
13
13
  "#{data.klass.model_name.human}_#{Time.now.to_i}"
14
14
  else
15
- Time.now.to_i
15
+ Time.now.to_i.to_s
16
16
  end
17
17
 
18
18
  options[:filename] = options[:filename] ? options[:filename].strip.sub(/\.xlsx$/i, "") : "data"
@@ -0,0 +1,8 @@
1
+ module XlsxtreamRails
2
+ module ClassMethods
3
+ # TODO
4
+ def to_xlsx
5
+ column_names.map { |x| x.to_sym }
6
+ end
7
+ end
8
+ end
@@ -10,13 +10,13 @@ module XlsxtreamRails
10
10
  instance_cols = instance.xlsx_columns
11
11
  instance_cols.each_with_index do |x, i|
12
12
  if x.is_a?(Array)
13
- headers.push(x[0].to_s) if needs_headers
13
+ headers.push(i18n_attr(instance, x[0])) if needs_headers
14
14
  row_data.push(x[1].is_a?(Symbol) ? instance.send(x[1]) : x[1])
15
15
  if needs_column_types
16
16
  column_types[i] = x[2]
17
17
  end
18
18
  else
19
- headers.push(str_titleize(x.to_s)) if needs_headers
19
+ headers.push(i18n_attr(instance, x)) if needs_headers
20
20
  row_data.push(x.is_a?(Symbol) ? instance.send(x) : x)
21
21
  end
22
22
  end
@@ -27,11 +27,9 @@ module XlsxtreamRails
27
27
  end
28
28
  end
29
29
 
30
- def self.str_titleize(str)
31
- str.sub(/\A_+/, "")
32
- .gsub(/[_.]/, " ")
33
- .sub(" rescue nil", "")
34
- .gsub(/(\A|\ )\w/) { |x| x.upcase }
30
+ def self.i18n_attr(instance, attr)
31
+ attr = attr.is_a?(Symbol) ? attr : attr.to_sym
32
+ instance.class.human_attribute_name(attr)
35
33
  end
36
34
  end
37
35
  end
@@ -1,3 +1,3 @@
1
1
  module XlsxtreamRails
2
- VERSION = "0.4.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -1,11 +1,15 @@
1
1
  require "xlsxtream"
2
+ require "xlsxtream_rails/class_methods"
2
3
  require "xlsxtream_rails/utils"
3
4
  require "xlsxtream_rails/version"
4
5
  require "xlsxtream_rails/railtie"
5
6
 
6
7
  module XlsxtreamRails
8
+ def self.included(base)
9
+ base.send(:extend, ClassMethods)
10
+ end
11
+
7
12
  def xlsx_columns(opts = {})
8
- column_names = self.class.column_names
9
- column_names.map { |x| x.to_sym }
13
+ self.class.to_xlsx
10
14
  end
11
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlsxtream_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - doabit
@@ -51,6 +51,7 @@ files:
51
51
  - lib/tasks/xlsxtream_rails_tasks.rake
52
52
  - lib/xlsxtream_rails.rb
53
53
  - lib/xlsxtream_rails/action_controller.rb
54
+ - lib/xlsxtream_rails/class_methods.rb
54
55
  - lib/xlsxtream_rails/railtie.rb
55
56
  - lib/xlsxtream_rails/utils.rb
56
57
  - lib/xlsxtream_rails/version.rb