caxlsx 3.3.0 → 4.5.0

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.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -11
  3. data/README.md +43 -16
  4. data/Rakefile +5 -11
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +15 -10
  7. data/lib/axlsx/content_type/content_type.rb +8 -10
  8. data/lib/axlsx/content_type/default.rb +7 -6
  9. data/lib/axlsx/content_type/override.rb +6 -5
  10. data/lib/axlsx/doc_props/app.rb +96 -32
  11. data/lib/axlsx/doc_props/core.rb +9 -12
  12. data/lib/axlsx/drawing/area_chart.rb +16 -17
  13. data/lib/axlsx/drawing/area_series.rb +23 -18
  14. data/lib/axlsx/drawing/ax_data_source.rb +4 -7
  15. data/lib/axlsx/drawing/axes.rb +11 -10
  16. data/lib/axlsx/drawing/axis.rb +83 -36
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +30 -21
  18. data/lib/axlsx/drawing/bar_chart.rb +29 -20
  19. data/lib/axlsx/drawing/bar_series.rb +23 -18
  20. data/lib/axlsx/drawing/bubble_chart.rb +9 -10
  21. data/lib/axlsx/drawing/bubble_series.rb +11 -12
  22. data/lib/axlsx/drawing/cat_axis.rb +38 -28
  23. data/lib/axlsx/drawing/chart.rb +52 -30
  24. data/lib/axlsx/drawing/d_lbls.rb +36 -32
  25. data/lib/axlsx/drawing/drawing.rb +61 -62
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  27. data/lib/axlsx/drawing/hyperlink.rb +22 -14
  28. data/lib/axlsx/drawing/line_3D_chart.rb +15 -17
  29. data/lib/axlsx/drawing/line_chart.rb +16 -17
  30. data/lib/axlsx/drawing/line_series.rb +23 -18
  31. data/lib/axlsx/drawing/marker.rb +29 -16
  32. data/lib/axlsx/drawing/num_data.rb +13 -16
  33. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  34. data/lib/axlsx/drawing/num_val.rb +10 -11
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +16 -10
  36. data/lib/axlsx/drawing/pic.rb +68 -24
  37. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +9 -12
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +26 -17
  41. data/lib/axlsx/drawing/scaling.rb +26 -13
  42. data/lib/axlsx/drawing/scatter_chart.rb +10 -11
  43. data/lib/axlsx/drawing/scatter_series.rb +17 -18
  44. data/lib/axlsx/drawing/ser_axis.rb +22 -19
  45. data/lib/axlsx/drawing/series.rb +14 -8
  46. data/lib/axlsx/drawing/series_title.rb +6 -6
  47. data/lib/axlsx/drawing/str_data.rb +10 -13
  48. data/lib/axlsx/drawing/str_val.rb +8 -9
  49. data/lib/axlsx/drawing/title.rb +23 -27
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +9 -9
  51. data/lib/axlsx/drawing/val_axis.rb +7 -8
  52. data/lib/axlsx/drawing/view_3D.rb +38 -30
  53. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  54. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  55. data/lib/axlsx/package.rb +134 -99
  56. data/lib/axlsx/rels/relationship.rb +42 -30
  57. data/lib/axlsx/rels/relationships.rb +9 -10
  58. data/lib/axlsx/stylesheet/border.rb +16 -8
  59. data/lib/axlsx/stylesheet/border_pr.rb +24 -12
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +44 -21
  61. data/lib/axlsx/stylesheet/cell_protection.rb +13 -7
  62. data/lib/axlsx/stylesheet/cell_style.rb +36 -15
  63. data/lib/axlsx/stylesheet/color.rb +23 -14
  64. data/lib/axlsx/stylesheet/dxf.rb +36 -15
  65. data/lib/axlsx/stylesheet/fill.rb +7 -6
  66. data/lib/axlsx/stylesheet/font.rb +71 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +16 -10
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -6
  69. data/lib/axlsx/stylesheet/num_fmt.rb +15 -14
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +20 -8
  71. data/lib/axlsx/stylesheet/styles.rb +167 -118
  72. data/lib/axlsx/stylesheet/table_style.rb +20 -10
  73. data/lib/axlsx/stylesheet/table_style_element.rb +16 -8
  74. data/lib/axlsx/stylesheet/table_styles.rb +16 -11
  75. data/lib/axlsx/stylesheet/theme.rb +163 -0
  76. data/lib/axlsx/stylesheet/xf.rb +78 -25
  77. data/lib/axlsx/util/accessors.rb +13 -11
  78. data/lib/axlsx/util/buffered_zip_output_stream.rb +64 -0
  79. data/lib/axlsx/util/constants.rb +133 -110
  80. data/lib/axlsx/util/mime_type_utils.rb +75 -5
  81. data/lib/axlsx/util/options_parser.rb +4 -3
  82. data/lib/axlsx/util/serialized_attributes.rb +47 -23
  83. data/lib/axlsx/util/simple_typed_list.rb +77 -64
  84. data/lib/axlsx/util/storage.rb +38 -41
  85. data/lib/axlsx/util/uri_utils.rb +70 -0
  86. data/lib/axlsx/util/validators.rb +111 -48
  87. data/lib/axlsx/util/zip_command.rb +10 -12
  88. data/lib/axlsx/version.rb +3 -2
  89. data/lib/axlsx/workbook/defined_name.rb +13 -9
  90. data/lib/axlsx/workbook/defined_names.rb +5 -4
  91. data/lib/axlsx/workbook/shared_strings_table.rb +13 -14
  92. data/lib/axlsx/workbook/workbook.rb +152 -120
  93. data/lib/axlsx/workbook/workbook_view.rb +9 -12
  94. data/lib/axlsx/workbook/workbook_views.rb +5 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +87 -15
  96. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +16 -10
  97. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +28 -25
  98. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  99. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +54 -0
  100. data/lib/axlsx/workbook/worksheet/border_creator.rb +34 -29
  101. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  102. data/lib/axlsx/workbook/worksheet/cell.rb +125 -78
  103. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +33 -29
  104. data/lib/axlsx/workbook/worksheet/cfvo.rb +13 -5
  105. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  106. data/lib/axlsx/workbook/worksheet/col.rb +32 -19
  107. data/lib/axlsx/workbook/worksheet/col_breaks.rb +9 -8
  108. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  109. data/lib/axlsx/workbook/worksheet/cols.rb +10 -8
  110. data/lib/axlsx/workbook/worksheet/comment.rb +14 -13
  111. data/lib/axlsx/workbook/worksheet/comments.rb +11 -13
  112. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +19 -9
  113. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +75 -22
  114. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  116. data/lib/axlsx/workbook/worksheet/data_validation.rb +73 -33
  117. data/lib/axlsx/workbook/worksheet/data_validations.rb +8 -9
  118. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  119. data/lib/axlsx/workbook/worksheet/dimension.rb +10 -7
  120. data/lib/axlsx/workbook/worksheet/header_footer.rb +5 -4
  121. data/lib/axlsx/workbook/worksheet/icon_set.rb +40 -12
  122. data/lib/axlsx/workbook/worksheet/merged_cells.rb +11 -11
  123. data/lib/axlsx/workbook/worksheet/outline_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_margins.rb +41 -13
  125. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -6
  126. data/lib/axlsx/workbook/worksheet/page_setup.rb +153 -131
  127. data/lib/axlsx/workbook/worksheet/pane.rb +34 -26
  128. data/lib/axlsx/workbook/worksheet/pivot_table.rb +78 -29
  129. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  130. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +6 -5
  131. data/lib/axlsx/workbook/worksheet/print_options.rb +4 -2
  132. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  133. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +13 -11
  134. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  135. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +66 -28
  136. data/lib/axlsx/workbook/worksheet/row.rb +34 -23
  137. data/lib/axlsx/workbook/worksheet/row_breaks.rb +9 -8
  138. data/lib/axlsx/workbook/worksheet/selection.rb +22 -16
  139. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +11 -7
  140. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  141. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  142. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +12 -8
  143. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +22 -21
  144. data/lib/axlsx/workbook/worksheet/sheet_view.rb +71 -55
  145. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  146. data/lib/axlsx/workbook/worksheet/table_style_info.rb +8 -6
  147. data/lib/axlsx/workbook/worksheet/tables.rb +8 -6
  148. data/lib/axlsx/workbook/worksheet/worksheet.rb +120 -79
  149. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +13 -11
  150. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  151. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +12 -10
  152. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +9 -7
  153. data/lib/axlsx.rb +120 -60
  154. data/lib/caxlsx.rb +3 -2
  155. metadata +42 -75
@@ -1,6 +1,6 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # App represents the app.xml document. The attributes for this object are primarily managed by the application the end user uses to edit the document. None of the attributes are required to serialize a valid xlsx object.
5
5
  # @see shared-documentPropertiesExtended.xsd
6
6
  # @note Support is not implemented for the following complex types:
@@ -10,7 +10,6 @@ module Axlsx
10
10
  # HLinks (VectorVariant),
11
11
  # DigSig (DigSigBlob)
12
12
  class App
13
-
14
13
  include Axlsx::OptionsParser
15
14
 
16
15
  # Creates an App object
@@ -36,7 +35,7 @@ module Axlsx
36
35
  # @option options [String] application
37
36
  # @option options [String] app_version
38
37
  # @option options [Integer] doc_security
39
- def initialize(options={})
38
+ def initialize(options = {})
40
39
  parse_options options
41
40
  end
42
41
 
@@ -76,7 +75,7 @@ module Axlsx
76
75
  attr_reader :paragraphs
77
76
  alias :Paragraphs :paragraphs
78
77
 
79
- # @return [Intger] The number of slides in the document.
78
+ # @return [Integer] The number of slides in the document.
80
79
  attr_reader :slides
81
80
  alias :Slides :slides
82
81
 
@@ -122,7 +121,7 @@ module Axlsx
122
121
 
123
122
  # @return [String] The name of the application
124
123
  attr_reader :application
125
- alias :Applicatoin :application
124
+ alias :Application :application
126
125
 
127
126
  # @return [String] The version of the application.
128
127
  attr_reader :app_version
@@ -133,103 +132,168 @@ module Axlsx
133
132
  alias :DocSecurity :doc_security
134
133
 
135
134
  # Sets the template property of your app.xml file
136
- def template=(v) Axlsx::validate_string v; @template = v; end
135
+ def template=(v)
136
+ Axlsx.validate_string v
137
+ @template = v
138
+ end
137
139
  alias :Template= :template=
138
140
 
139
141
  # Sets the manager property of your app.xml file
140
- def manager=(v) Axlsx::validate_string v; @manager = v; end
142
+ def manager=(v)
143
+ Axlsx.validate_string v
144
+ @manager = v
145
+ end
141
146
  alias :Manager= :manager=
142
147
 
143
148
  # Sets the company property of your app.xml file
144
- def company=(v) Axlsx::validate_string v; @company = v; end
149
+ def company=(v)
150
+ Axlsx.validate_string v
151
+ @company = v
152
+ end
145
153
  alias :Company= :company=
154
+
146
155
  # Sets the pages property of your app.xml file
147
- def pages=(v) Axlsx::validate_int v; @pages = v; end
156
+ def pages=(v)
157
+ Axlsx.validate_int v
158
+ @pages = v
159
+ end
148
160
 
149
161
  # Sets the words property of your app.xml file
150
- def words=(v) Axlsx::validate_int v; @words = v; end
162
+ def words=(v)
163
+ Axlsx.validate_int v
164
+ @words = v
165
+ end
151
166
  alias :Words= :words=
152
167
 
153
168
  # Sets the characters property of your app.xml file
154
- def characters=(v) Axlsx::validate_int v; @characters = v; end
169
+ def characters=(v)
170
+ Axlsx.validate_int v
171
+ @characters = v
172
+ end
155
173
  alias :Characters= :characters=
156
174
 
157
175
  # Sets the presentation_format property of your app.xml file
158
- def presentation_format=(v) Axlsx::validate_string v; @presentation_format = v; end
176
+ def presentation_format=(v)
177
+ Axlsx.validate_string v
178
+ @presentation_format = v
179
+ end
159
180
  alias :PresentationFormat= :presentation_format=
160
181
 
161
182
  # Sets the lines property of your app.xml file
162
- def lines=(v) Axlsx::validate_int v; @lines = v; end
183
+ def lines=(v)
184
+ Axlsx.validate_int v
185
+ @lines = v
186
+ end
163
187
  alias :Lines= :lines=
164
188
 
165
189
  # Sets the paragraphs property of your app.xml file
166
- def paragraphs=(v) Axlsx::validate_int v; @paragraphs = v; end
190
+ def paragraphs=(v)
191
+ Axlsx.validate_int v
192
+ @paragraphs = v
193
+ end
167
194
  alias :Paragraphs= :paragraphs=
168
195
 
169
196
  # sets the slides property of your app.xml file
170
- def slides=(v) Axlsx::validate_int v; @slides = v; end
197
+ def slides=(v)
198
+ Axlsx.validate_int v
199
+ @slides = v
200
+ end
171
201
  alias :Slides= :slides=
172
202
 
173
203
  # sets the notes property of your app.xml file
174
- def notes=(v) Axlsx::validate_int v; @notes = v; end
204
+ def notes=(v)
205
+ Axlsx.validate_int v
206
+ @notes = v
207
+ end
175
208
  alias :Notes= :notes=
176
209
 
177
210
  # Sets the total_time property of your app.xml file
178
- def total_time=(v) Axlsx::validate_int v; @total_time = v; end
211
+ def total_time=(v)
212
+ Axlsx.validate_int v
213
+ @total_time = v
214
+ end
179
215
  alias :TotalTime= :total_time=
180
216
 
181
217
  # Sets the hidden_slides property of your app.xml file
182
- def hidden_slides=(v) Axlsx::validate_int v; @hidden_slides = v; end
218
+ def hidden_slides=(v)
219
+ Axlsx.validate_int v
220
+ @hidden_slides = v
221
+ end
183
222
  alias :HiddenSlides= :hidden_slides=
184
223
 
185
224
  # Sets the m_m_clips property of your app.xml file
186
- def m_m_clips=(v) Axlsx::validate_int v; @m_m_clips = v; end
225
+ def m_m_clips=(v)
226
+ Axlsx.validate_int v
227
+ @m_m_clips = v
228
+ end
187
229
  alias :MMClips= :m_m_clips=
188
230
 
189
231
  # Sets the scale_crop property of your app.xml file
190
- def scale_crop=(v) Axlsx::validate_boolean v; @scale_crop = v; end
232
+ def scale_crop=(v)
233
+ Axlsx.validate_boolean v
234
+ @scale_crop = v
235
+ end
191
236
  alias :ScaleCrop= :scale_crop=
192
237
 
193
238
  # Sets the links_up_to_date property of your app.xml file
194
- def links_up_to_date=(v) Axlsx::validate_boolean v; @links_up_to_date = v; end
239
+ def links_up_to_date=(v)
240
+ Axlsx.validate_boolean v
241
+ @links_up_to_date = v
242
+ end
195
243
  alias :LinksUpToDate= :links_up_to_date=
196
244
 
197
245
  # Sets the characters_with_spaces property of your app.xml file
198
- def characters_with_spaces=(v) Axlsx::validate_int v; @characters_with_spaces = v; end
246
+ def characters_with_spaces=(v)
247
+ Axlsx.validate_int v
248
+ @characters_with_spaces = v
249
+ end
199
250
  alias :CharactersWithSpaces= :characters_with_spaces=
200
251
 
201
252
  # Sets the share_doc property of your app.xml file
202
- def shared_doc=(v) Axlsx::validate_boolean v; @shared_doc = v; end
253
+ def shared_doc=(v)
254
+ Axlsx.validate_boolean v
255
+ @shared_doc = v
256
+ end
203
257
  alias :SharedDoc= :shared_doc=
204
258
 
205
259
  # Sets the hyperlink_base property of your app.xml file
206
- def hyperlink_base=(v) Axlsx::validate_string v; @hyperlink_base = v; end
260
+ def hyperlink_base=(v)
261
+ Axlsx.validate_string v
262
+ @hyperlink_base = v
263
+ end
207
264
  alias :HyperlinkBase= :hyperlink_base=
208
265
 
209
266
  # Sets the HyperLinksChanged property of your app.xml file
210
- def hyperlinks_changed=(v) Axlsx::validate_boolean v; @hyperlinks_changed = v; end
267
+ def hyperlinks_changed=(v)
268
+ Axlsx.validate_boolean v
269
+ @hyperlinks_changed = v
270
+ end
211
271
  alias :HyperLinksChanged= :hyperlinks_changed=
212
272
 
213
273
  # Sets the app_version property of your app.xml file
214
- def app_version=(v) Axlsx::validate_string v; @app_version = v; end
274
+ def app_version=(v)
275
+ Axlsx.validate_string v
276
+ @app_version = v
277
+ end
215
278
  alias :AppVersion= :app_version=
216
279
 
217
280
  # Sets the doc_security property of your app.xml file
218
- def doc_security=(v) Axlsx::validate_int v; @doc_security = v; end
281
+ def doc_security=(v)
282
+ Axlsx.validate_int v
283
+ @doc_security = v
284
+ end
219
285
  alias :DocSecurity= :doc_security=
220
286
 
221
287
  # Serialize the app.xml document
222
288
  # @return [String]
223
- def to_xml_string(str = '')
289
+ def to_xml_string(str = +'')
224
290
  str << '<?xml version="1.0" encoding="UTF-8"?>'
225
- str << ('<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">')
291
+ str << '<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">'
226
292
  Axlsx.instance_values_for(self).each do |key, value|
227
293
  node_name = Axlsx.camel(key)
228
294
  str << "<#{node_name}>#{value}</#{node_name}>"
229
295
  end
230
296
  str << '</Properties>'
231
297
  end
232
-
233
298
  end
234
-
235
299
  end
@@ -1,15 +1,14 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # The core object for the package.
5
5
  # @note Packages manage their own core object.
6
6
  # @see Package#core
7
7
  class Core
8
-
9
8
  # Creates a new Core object.
10
9
  # @option options [String] creator
11
10
  # @option options [Time] created
12
- def initialize(options={})
11
+ def initialize(options = {})
13
12
  @creator = options[:creator] || 'axlsx'
14
13
  @created = options[:created]
15
14
  end
@@ -23,17 +22,15 @@ module Axlsx
23
22
 
24
23
  # serializes the core.xml document
25
24
  # @return [String]
26
- def to_xml_string(str = '')
25
+ def to_xml_string(str = +'')
27
26
  str << '<?xml version="1.0" encoding="UTF-8"?>'
28
- str << ('<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" ')
29
- str << ('xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" ')
30
- str << ('xmlns:xsi="' << CORE_NS_XSI << '">')
31
- str << ('<dc:creator>' << self.creator << '</dc:creator>')
32
- str << ('<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>')
27
+ str << '<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" '
28
+ str << 'xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" '
29
+ str << 'xmlns:xsi="' << CORE_NS_XSI << '">'
30
+ str << '<dc:creator>' << creator << '</dc:creator>'
31
+ str << '<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>'
33
32
  str << '<cp:revision>0</cp:revision>'
34
33
  str << '</cp:coreProperties>'
35
34
  end
36
-
37
35
  end
38
-
39
36
  end
@@ -1,7 +1,7 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
4
- # The AreaChart is a two dimentional line chart (who would have guessed?) that you can add to your worksheet.
3
+ module Axlsx
4
+ # The AreaChart is a two dimensional line chart (who would have guessed?) that you can add to your worksheet.
5
5
  # @example Creating a chart
6
6
  # # This example creates a line in a single sheet.
7
7
  # require "rubygems" # if that is your preferred way to manage gems!
@@ -20,7 +20,6 @@ module Axlsx
20
20
  # @see Series
21
21
  # @see Package#serialize
22
22
  class AreaChart < Chart
23
-
24
23
  # the category axis
25
24
  # @return [CatAxis]
26
25
  def cat_axis
@@ -35,7 +34,7 @@ module Axlsx
35
34
  end
36
35
  alias :valAxis :val_axis
37
36
 
38
- # must be one of [:percentStacked, :clustered, :standard, :stacked]
37
+ # must be one of [:percentStacked, :clustered, :standard, :stacked]
39
38
  # @return [Symbol]
40
39
  attr_reader :grouping
41
40
 
@@ -45,10 +44,10 @@ module Axlsx
45
44
  # @option options [Boolean] show_legend
46
45
  # @option options [Symbol] grouping
47
46
  # @see Chart
48
- def initialize(frame, options={})
47
+ def initialize(frame, options = {})
49
48
  @vary_colors = false
50
49
  @grouping = :standard
51
- super(frame, options)
50
+ super
52
51
  @series_type = AreaSeries
53
52
  @d_lbls = nil
54
53
  end
@@ -64,9 +63,9 @@ module Axlsx
64
63
  # chart based on the actual class type and not a fixed node name.
65
64
  # @return [String]
66
65
  def node_name
67
- path = self.class.to_s
66
+ path = self.class.name
68
67
  if i = path.rindex('::')
69
- path = path[(i+2)..-1]
68
+ path = path[(i + 2)..-1]
70
69
  end
71
70
  path[0] = path[0].chr.downcase
72
71
  path
@@ -75,16 +74,16 @@ module Axlsx
75
74
  # Serializes the object
76
75
  # @param [String] str
77
76
  # @return [String]
78
- def to_xml_string(str = '')
79
- super(str) do
80
- str << ("<c:" << node_name << ">")
81
- str << ('<c:grouping val="' << grouping.to_s << '"/>')
82
- str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
77
+ def to_xml_string(str = +'')
78
+ super do
79
+ str << "<c:" << node_name << ">"
80
+ str << '<c:grouping val="' << grouping.to_s << '"/>'
81
+ str << '<c:varyColors val="' << vary_colors.to_s << '"/>'
83
82
  @series.each { |ser| ser.to_xml_string(str) }
84
83
  @d_lbls.to_xml_string(str) if @d_lbls
85
84
  yield if block_given?
86
- axes.to_xml_string(str, :ids => true)
87
- str << ("</c:" << node_name << ">")
85
+ axes.to_xml_string(str, ids: true)
86
+ str << "</c:" << node_name << ">"
88
87
  axes.to_xml_string(str)
89
88
  end
90
89
  end
@@ -93,7 +92,7 @@ module Axlsx
93
92
  # axis.
94
93
  # @return [Axes]
95
94
  def axes
96
- @axes ||= Axes.new(:cat_axis => CatAxis, :val_axis => ValAxis)
95
+ @axes ||= Axes.new(cat_axis: CatAxis, val_axis: ValAxis)
97
96
  end
98
97
  end
99
98
  end
@@ -1,11 +1,11 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A AreaSeries defines the title, data and labels for line charts
4
5
  # @note The recommended way to manage series is to use Chart#add_series
5
6
  # @see Worksheet#add_chart
6
7
  # @see Chart#add_series
7
8
  class AreaSeries < Series
8
-
9
9
  # The data for this series.
10
10
  # @return [ValAxisData]
11
11
  attr_reader :data
@@ -35,13 +35,13 @@ module Axlsx
35
35
  # @option options [Array, SimpleTypedList] data
36
36
  # @option options [Array, SimpleTypedList] labels
37
37
  # @param [Chart] chart
38
- def initialize(chart, options={})
38
+ def initialize(chart, options = {})
39
39
  @show_marker = false
40
- @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default
40
+ @marker_symbol = options[:marker_symbol] || :default
41
41
  @smooth = false
42
42
  @labels, @data = nil, nil
43
- super(chart, options)
44
- @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
43
+ super
44
+ @labels = AxDataSource.new(data: options[:labels]) unless options[:labels].nil?
45
45
  @data = NumDataSource.new(options) unless options[:data].nil?
46
46
  end
47
47
 
@@ -52,34 +52,34 @@ module Axlsx
52
52
 
53
53
  # @see show_marker
54
54
  def show_marker=(v)
55
- Axlsx::validate_boolean(v)
55
+ Axlsx.validate_boolean(v)
56
56
  @show_marker = v
57
57
  end
58
58
 
59
59
  # @see marker_symbol
60
60
  def marker_symbol=(v)
61
- Axlsx::validate_marker_symbol(v)
61
+ Axlsx.validate_marker_symbol(v)
62
62
  @marker_symbol = v
63
63
  end
64
64
 
65
65
  # @see smooth
66
66
  def smooth=(v)
67
- Axlsx::validate_boolean(v)
67
+ Axlsx.validate_boolean(v)
68
68
  @smooth = v
69
69
  end
70
70
 
71
71
  # Serializes the object
72
72
  # @param [String] str
73
73
  # @return [String]
74
- def to_xml_string(str = '')
75
- super(str) do
74
+ def to_xml_string(str = +'')
75
+ super do
76
76
  if color
77
77
  str << '<c:spPr><a:solidFill>'
78
- str << ('<a:srgbClr val="' << color << '"/>')
78
+ str << '<a:srgbClr val="' << color << '"/>'
79
79
  str << '</a:solidFill>'
80
80
  str << '<a:ln w="28800">'
81
81
  str << '<a:solidFill>'
82
- str << ('<a:srgbClr val="' << color << '"/>')
82
+ str << '<a:srgbClr val="' << color << '"/>'
83
83
  str << '</a:solidFill>'
84
84
  str << '</a:ln>'
85
85
  str << '<a:round/>'
@@ -89,22 +89,27 @@ module Axlsx
89
89
  if !@show_marker
90
90
  str << '<c:marker><c:symbol val="none"/></c:marker>'
91
91
  elsif @marker_symbol != :default
92
- str << '<c:marker><c:symbol val="' + @marker_symbol.to_s + '"/></c:marker>'
92
+ str << '<c:marker><c:symbol val="' << @marker_symbol.to_s << '"/></c:marker>'
93
93
  end
94
94
 
95
95
  @labels.to_xml_string(str) unless @labels.nil?
96
96
  @data.to_xml_string(str) unless @data.nil?
97
- str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
97
+ str << '<c:smooth val="' << (smooth ? '1' : '0') << '"/>'
98
98
  end
99
99
  end
100
100
 
101
101
  private
102
102
 
103
103
  # assigns the data for this series
104
- def data=(v) DataTypeValidator.validate "Series.data", [NumDataSource], v; @data = v; end
104
+ def data=(v)
105
+ DataTypeValidator.validate "Series.data", [NumDataSource], v
106
+ @data = v
107
+ end
105
108
 
106
109
  # assigns the labels for this series
107
- def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
108
-
110
+ def labels=(v)
111
+ DataTypeValidator.validate "Series.labels", [AxDataSource], v
112
+ @labels = v
113
+ end
109
114
  end
110
115
  end
@@ -1,17 +1,17 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # An axis data source that can contain referenced or literal strings or numbers
4
5
  # @note only string data types are supported - mainly because we have not implemented a chart type that requires a numerical axis value
5
6
  class AxDataSource < NumDataSource
6
-
7
7
  # creates a new NumDataSource object
8
8
  # @option options [Array] data An array of Cells or Numeric objects
9
9
  # @option options [Symbol] tag_name see tag_name
10
- def initialize(options={})
10
+ def initialize(options = {})
11
11
  @tag_name = :cat
12
12
  @data_type = StrData
13
13
  @ref_tag_name = :strRef
14
- super(options)
14
+ super
15
15
  end
16
16
 
17
17
  # allowed element tag names for serialization
@@ -19,8 +19,5 @@ module Axlsx
19
19
  def self.allowed_tag_names
20
20
  [:xVal, :cat]
21
21
  end
22
-
23
22
  end
24
-
25
23
  end
26
-
@@ -1,22 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
-
3
4
  # The Axes class creates and manages axis information and
4
5
  # serialization for charts.
5
6
  class Axes
6
-
7
7
  # @param [Hash] options options used to generate axis each key
8
8
  # should be an axis name like :val_axis and its value should be the
9
9
  # class of the axis type to construct. The :cat_axis, if there is one,
10
10
  # must come first (we assume a Ruby 1.9+ Hash or an OrderedHash).
11
- def initialize(options={})
12
- raise(ArgumentError, "CatAxis must come first") if options.keys.include?(:cat_axis) && options.keys.first != :cat_axis
11
+ def initialize(options = {})
12
+ raise(ArgumentError, "CatAxis must come first") if options.key?(:cat_axis) && options.keys.first != :cat_axis
13
+
13
14
  options.each do |name, axis_class|
14
15
  add_axis(name, axis_class)
15
16
  end
16
17
  end
17
18
 
18
- # [] provides assiciative access to a specic axis store in an axes
19
- # instance.
19
+ # [] provides associative access to a specific axis store in an axes
20
+ # instance.
20
21
  # @return [Axis]
21
22
  def [](name)
22
23
  axes.assoc(name)[1]
@@ -27,12 +28,12 @@ module Axlsx
27
28
  # @param [Hash] options
28
29
  # @option options ids
29
30
  # If the ids option is specified only the axis identifier is
30
- # serialized. Otherwise, each axis is serialized in full.
31
- def to_xml_string(str = '', options = {})
31
+ # serialized. Otherwise, each axis is serialized in full.
32
+ def to_xml_string(str = +'', options = {})
32
33
  if options[:ids]
33
34
  # CatAxis must come first in the XML (for Microsoft Excel at least)
34
- sorted = axes.sort_by { |name, axis| axis.kind_of?(CatAxis) ? 0 : 1 }
35
- sorted.each { |axis| str << ('<c:axId val="' << axis[1].id.to_s << '"/>') }
35
+ sorted = axes.sort_by { |_name, axis| axis.is_a?(CatAxis) ? 0 : 1 }
36
+ sorted.each { |axis| str << '<c:axId val="' << axis[1].id.to_s << '"/>' }
36
37
  else
37
38
  axes.each { |axis| axis[1].to_xml_string(str) }
38
39
  end