spreadsheet_architect 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c70bffeb66b07a08e65d84e41b84a47595926571
4
- data.tar.gz: f70ea264d22245f9771e36eb9bc46d22c05e5f7e
3
+ metadata.gz: be2d251d985ed779019709a19cd14047e8f26c18
4
+ data.tar.gz: 5076391ee7d477af958ef6f9dd1cbc438695c57a
5
5
  SHA512:
6
- metadata.gz: 72c104868f8995b133f3337646ef59f739017ba8306bc31ad0d1d263341ef9c6984730adb3904484563c2f6553d82c8bb3d6b90e61970e3ccbcefe0828caa7c1
7
- data.tar.gz: 2d7dbe940b6e56f54b902845fc21a94f75c14296aeb075aff2bc13ab9278a3d1c2f5a6706e497759c47dcd97f906ad24d9dccd3424b133d085b9210920072803
6
+ metadata.gz: 87ea6396eb5bed677c7fce4bec9da8588620ecd247ea4bbb9fbf964908809803f27e7959527917a8a404b981f60c31d025b76ea92c16856e0f06f36e84f21790
7
+ data.tar.gz: 3c5022fd0922a7c2fc2eeec0fbdce445b75ef9a8439b561d412b6c1564b9091de5f89f4d4db414e4243cbe83efb961c2baa881a93474a765884a55c09483306b
data/README.md CHANGED
@@ -105,31 +105,21 @@ end
105
105
  ### to_xlsx
106
106
  **sheet_name** - *String*
107
107
 
108
- **header_style** - *Hash* - Default: `{bg_color: "AAAAAA", fg_color: "FFFFFF", alignment: { horizontal: :center }, bold: true}`
108
+ **header_style** - *Hash* - Default: `{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`
109
109
 
110
- **row_style** - Hash
110
+ **row_style** - Hash - Default: `{background_color: "FFFFFF", color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`
111
111
 
112
112
  ### to_ods
113
113
  **sheet_name** - *String*
114
114
 
115
- **header_style** - *Hash* - Default: {bold: true} - Note: Currently only supports bold & fg_color style options
115
+ **header_style** - *Hash* - Default: {color: "000000", align: :center, font_size: 10, bold: true} - Note: Currently only supports these options
116
116
 
117
- **row_style** - *Hash*
117
+ **row_style** - *Hash* - Default: {color: "000000", align: :left, font_size: 10, bold: false} - Note: Currently only supports these options
118
118
 
119
119
  ### to_csv
120
120
  Only the generic options
121
121
 
122
122
 
123
- # Style Options
124
- **bg_color** - *6 Digit Hex Color without the # Symbol* - Ex. "AAAAAAA"
125
-
126
- **fg_color** - *Text Color - 6 Digit Hex Color without the # Symbol* - Ex. "0000000"
127
-
128
- **alignment** - *Hash* - Ex. {horizontal: :right, vertical: :top}
129
-
130
- **bold** - *Boolean*
131
-
132
-
133
123
  # Credits
134
124
  Created by Weston Ganger - @westonganger
135
125
 
@@ -44,17 +44,20 @@ module SpreadsheetArchitect
44
44
 
45
45
  headers = (options[:headers] == false ? false : headers)
46
46
 
47
+ header_style = {background_color: "AAAAAA", color: "FFFFFF", align: :center, bold: false, font_name: 'Arial', font_size: 10, italic: false, underline: false}
48
+
47
49
  if options[:header_style]
48
- header_style = options[:header_style]
50
+ header_style.merge!(options[:header_style])
49
51
  elsif options[:header_style] == false
50
52
  header_style = false
51
53
  elsif options[:row_style]
52
54
  header_style = options[:row_style]
53
- else
54
- header_style = {bg_color: "AAAAAA", fg_color: "FFFFFF", alignment: { horizontal: :center }, bold: true}
55
55
  end
56
56
 
57
- row_style = options[:row_style]
57
+ row_style = {background_color: "FFFFFF", color: "000000", align: :left, bold: false, font_name: 'Arial', font_size: 10, italic: false, underline: false}
58
+ if options[:row_style]
59
+ row_style.merge!(options[:row_style])
60
+ end
58
61
 
59
62
  sheet_name = options[:sheet_name] || self.name
60
63
 
@@ -106,12 +109,17 @@ module SpreadsheetArchitect
106
109
 
107
110
  spreadsheet.office_style :header_style, family: :cell do
108
111
  if options[:header_style]
109
- if options[:header_style][:bold]
112
+ unless opts[:row_style] && opts[:row_style][:bold] == false #uses opts, temporary
110
113
  property :text, 'font-weight': :bold
111
- property :text, 'align': :center
112
114
  end
113
- if options[:header_style][:fg_color] && opts[:header_style] && opts[:header_style][:fg_color] #temporary
114
- property :text, 'color': "##{options[:header_style][:fg_color]}"
115
+ if options[:header_style][:align]
116
+ property :text, 'align': options[:header_style][:align]
117
+ end
118
+ if options[:header_style][:size]
119
+ property :text, 'font-size': options[:header_style][:size]
120
+ end
121
+ if options[:header_style][:color] && opts[:header_style] && opts[:header_style][:color] #temporary
122
+ property :text, 'color': "##{options[:header_style][:color]}"
115
123
  end
116
124
  end
117
125
  end
@@ -120,8 +128,14 @@ module SpreadsheetArchitect
120
128
  if options[:row_style][:bold]
121
129
  property :text, 'font-weight': :bold
122
130
  end
123
- if options[:row_style][:fg_color]
124
- property :text, 'color': "##{options[:header_style][:fg_color]}"
131
+ if options[:row_style][:align]
132
+ property :text, 'align': options[:row_style][:align]
133
+ end
134
+ if options[:row_style][:size]
135
+ property :text, 'font-size': options[:row_style][:size]
136
+ end
137
+ if opts[:row_style] && opts[:row_style][:color] #uses opts, temporary
138
+ property :text, 'color': "##{options[:row_style][:color]}"
125
139
  end
126
140
  end
127
141
  end
@@ -131,14 +145,14 @@ module SpreadsheetArchitect
131
145
  if options[:headers]
132
146
  row do
133
147
  options[:headers].each do |header|
134
- cell header, style: (:header_style if options[:header_style])
148
+ cell header, style: :header_style
135
149
  end
136
150
  end
137
151
  end
138
152
  options[:data].each do |x|
139
153
  row do
140
154
  this_class.sa_get_row_data(options[:columns], x).each do |y|
141
- cell y, style: (:row_style if options[:row_style])
155
+ cell y, style: :row_style
142
156
  end
143
157
  end
144
158
  end
@@ -149,18 +163,42 @@ module SpreadsheetArchitect
149
163
 
150
164
  def to_xlsx(opts={})
151
165
  options = sa_get_options(opts)
166
+
167
+ header_style = {}
168
+ header_style[:fg_color] = options[:header_style].delete(:color)
169
+ header_style[:bg_color] = options[:header_style].delete(:background_color)
170
+ if header_style[:align]
171
+ header_style[:alignment] = {}
172
+ header_style[:alignment][:horizontal] = options[:header_style][:align]
173
+ end
174
+ header_style[:b] = options[:header_style].delete(:bold)
175
+ header_style[:sz] = options[:header_style].delete(:font_size)
176
+ header_style[:i] = options[:header_style].delete(:italic)
177
+ header_style[:u] = options[:header_style].delete(:underline)
178
+
179
+ row_style = {}
180
+ row_style[:fg_color] = options[:row_style].delete(:color)
181
+ row_style[:bg_color] = options[:row_style].delete(:background_color)
182
+ if row_style[:align]
183
+ row_style[:alignment] = {}
184
+ row_style[:alignment][:horizontal] = options[:row_style][:align]
185
+ end
186
+ row_style[:b] = options[:row_style].delete(:bold)
187
+ row_style[:sz] = options[:row_style].delete(:font_size)
188
+ row_style[:i] = options[:row_style].delete(:italic)
189
+ row_style[:u] = options[:row_style].delete(:underline)
152
190
 
153
- package = opts[:package] || Axlsx::Package.new
191
+ package = Axlsx::Package.new
154
192
 
155
193
  return package if options[:data].empty?
156
194
 
157
195
  package.workbook.add_worksheet(name: options[:sheet_name]) do |sheet|
158
196
  if options[:headers]
159
- sheet.add_row options[:headers], style: (package.workbook.styles.add_style(options[:header_style]) if options[:header_style])
197
+ sheet.add_row options[:headers], style: package.workbook.styles.add_style(header_style)
160
198
  end
161
199
 
162
200
  options[:data].each do |x|
163
- sheet.add_row sa_get_row_data(options[:columns], x), style: (package.workbook.styles.add_style(options[:row_style]) if options[:row_style]), types: options[:types]
201
+ sheet.add_row sa_get_row_data(options[:columns], x), style: package.workbook.styles.add_style(row_style), types: options[:types]
164
202
  end
165
203
  end
166
204
 
@@ -1,3 +1,3 @@
1
1
  module SpreadsheetArchitect
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet_architect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-26 00:00:00.000000000 Z
11
+ date: 2016-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: axlsx