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,10 +1,10 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A graphic frame defines a container for a chart object
4
5
  # @note The recommended way to manage charts is Worksheet#add_chart
5
6
  # @see Worksheet#add_chart
6
7
  class GraphicFrame
7
-
8
8
  # A reference to the chart object associated with this frame
9
9
  # @return [Chart]
10
10
  attr_reader :chart
@@ -31,11 +31,11 @@ module Axlsx
31
31
  # Serializes the object
32
32
  # @param [String] str
33
33
  # @return [String]
34
- def to_xml_string(str = '')
34
+ def to_xml_string(str = +'')
35
35
  # macro attribute should be optional!
36
36
  str << '<xdr:graphicFrame>'
37
37
  str << '<xdr:nvGraphicFramePr>'
38
- str << ('<xdr:cNvPr id="' << @anchor.drawing.index.to_s << '" name="' << 'item_' << @anchor.drawing.index.to_s << '"/>')
38
+ str << '<xdr:cNvPr id="' << @anchor.drawing.index.to_s << '" name="' << 'item_' << @anchor.drawing.index.to_s << '"/>'
39
39
  str << '<xdr:cNvGraphicFramePr/>'
40
40
  str << '</xdr:nvGraphicFramePr>'
41
41
  str << '<xdr:xfrm>'
@@ -43,12 +43,11 @@ module Axlsx
43
43
  str << '<a:ext cx="0" cy="0"/>'
44
44
  str << '</xdr:xfrm>'
45
45
  str << '<a:graphic>'
46
- str << ('<a:graphicData uri="' << XML_NS_C << '">')
47
- str << ('<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="' << rId << '"/>')
46
+ str << '<a:graphicData uri="' << XML_NS_C << '">'
47
+ str << '<c:chart xmlns:c="' << XML_NS_C << '" xmlns:r="' << XML_NS_R << '" r:id="' << rId << '"/>'
48
48
  str << '</a:graphicData>'
49
49
  str << '</a:graphic>'
50
50
  str << '</xdr:graphicFrame>'
51
51
  end
52
-
53
52
  end
54
53
  end
@@ -1,25 +1,25 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # a hyperlink object adds an action to an image when clicked so that when the image is clicked the link is fecthed.
4
5
  # @note using the hyperlink option when calling add_image on a drawing object is the recommended way to manage hyperlinks
5
6
  # @see {file:README} README
6
7
  class Hyperlink
7
-
8
8
  include Axlsx::SerializedAttributes
9
9
  include Axlsx::OptionsParser
10
10
 
11
- #Creates a hyperlink object
11
+ # Creates a hyperlink object
12
12
  # parent must be a Pic for now, although I expect that other object support this tag and its cNvPr parent
13
13
  # @param [Pic] parent
14
14
  # @option options [String] tooltip message shown when hyperlinked object is hovered over with mouse.
15
15
  # @option options [String] tgtFrame Target frame for opening hyperlink
16
16
  # @option options [String] invalidUrl supposedly use to store the href when we know it is an invalid resource.
17
17
  # @option options [String] href the target resource this hyperlink links to. This is actually stored on the relationship.
18
- # @option options [String] action A string that can be used to perform specific actions. For excel please see this reference: http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
18
+ # @option options [String] action A string that can be used to perform specific actions. For Excel please see this reference: https://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
19
19
  # @option options [Boolean] endSnd terminate any sound events when processing this link
20
20
  # @option options [Boolean] history include this link in the list of visited links for the applications history.
21
21
  # @option options [Boolean] highlightClick indicate that the link has already been visited.
22
- def initialize(parent, options={})
22
+ def initialize(parent, options = {})
23
23
  DataTypeValidator.validate "Hyperlink.parent", [Pic], parent
24
24
  @parent = parent
25
25
  parse_options options
@@ -40,7 +40,7 @@ module Axlsx
40
40
  alias :invalidUrl :invalid_url
41
41
  alias :invalidUrl= :invalid_url=
42
42
 
43
- #An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see http://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
43
+ # An action to take when the link is clicked. The specification says "This can be used to specify a slide to be navigated to or a script of code to be run." but in most cases you will not need to do anything with this. MS does reserve a few interesting strings. @see https://msdn.microsoft.com/en-us/library/ff532419%28v=office.12%29.aspx
44
44
  # @return [String]
45
45
  attr_accessor :action
46
46
 
@@ -52,7 +52,10 @@ module Axlsx
52
52
  # @see endSnd
53
53
  # @param [Boolean] v The boolean value indicating the termination of playing sounds on click
54
54
  # @return [Boolean]
55
- def end_snd=(v) Axlsx::validate_boolean(v); @end_snd = v end
55
+ def end_snd=(v)
56
+ Axlsx.validate_boolean(v)
57
+ @end_snd = v
58
+ end
56
59
  alias :endSnd= :end_snd=
57
60
 
58
61
  # indicates that the link has already been clicked.
@@ -62,7 +65,10 @@ module Axlsx
62
65
 
63
66
  # @see highlightClick
64
67
  # @param [Boolean] v The value to assign
65
- def highlight_click=(v) Axlsx::validate_boolean(v); @highlight_click = v end
68
+ def highlight_click=(v)
69
+ Axlsx.validate_boolean(v)
70
+ @highlight_click = v
71
+ end
66
72
  alias :highlightClick= :highlight_click=
67
73
 
68
74
  # From the specs: Specifies whether to add this URI to the history when navigating to it. This allows for the viewing of this presentation without the storing of history information on the viewing machine. If this attribute is omitted, then a value of 1 or true is assumed.
@@ -70,8 +76,11 @@ module Axlsx
70
76
  attr_reader :history
71
77
 
72
78
  # @see history
73
- # param [Boolean] v The value to assing
74
- def history=(v) Axlsx::validate_boolean(v); @history = v end
79
+ # param [Boolean] v The value to assign
80
+ def history=(v)
81
+ Axlsx.validate_boolean(v)
82
+ @history = v
83
+ end
75
84
 
76
85
  # From the specs: Specifies the target frame that is to be used when opening this hyperlink. When the hyperlink is activated this attribute is used to determine if a new window is launched for viewing or if an existing one can be used. If this attribute is omitted, than a new window is opened.
77
86
  # @return [String]
@@ -86,15 +95,14 @@ module Axlsx
86
95
  # The relationship object for this hyperlink.
87
96
  # @return [Relationship]
88
97
  def relationship
89
- Relationship.new(self, HYPERLINK_R, href, :target_mode => :External)
98
+ Relationship.new(self, HYPERLINK_R, href, target_mode: :External)
90
99
  end
91
100
 
92
101
  # Serializes the object
93
102
  # @param [String] str
94
103
  # @return [String]
95
- def to_xml_string(str = '')
96
- serialized_tag 'a:hlinkClick', str, {:'r:id' => relationship.Id, :'xmlns:r' => XML_NS_R }
104
+ def to_xml_string(str = +'')
105
+ serialized_tag 'a:hlinkClick', str, { 'r:id': relationship.Id, 'xmlns:r': XML_NS_R }
97
106
  end
98
-
99
107
  end
100
108
  end
@@ -1,7 +1,7 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
4
- # The Line3DChart is a three dimentional line chart (who would have guessed?) that you can add to your worksheet.
3
+ module Axlsx
4
+ # The Line3DChart is a three 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,14 +20,13 @@ module Axlsx
20
20
  # @see Series
21
21
  # @see Package#serialize
22
22
  class Line3DChart < Axlsx::LineChart
23
-
24
23
  # space between bar or column clusters, as a percentage of the bar or column width.
25
24
  # @return [String]
26
25
  attr_reader :gap_depth
27
26
  alias :gapDepth :gap_depth
28
27
 
29
28
  # validation regex for gap amount percent
30
- GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/
29
+ GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/.freeze
31
30
 
32
31
  # the category axis
33
32
  # @return [Axis]
@@ -41,28 +40,27 @@ module Axlsx
41
40
  # @see Chart
42
41
  # @see lineChart
43
42
  # @see View3D
44
- def initialize(frame, options={})
43
+ def initialize(frame, options = {})
45
44
  @gap_depth = nil
46
- @view_3D = View3D.new({:r_ang_ax=>1}.merge(options))
47
- super(frame, options)
45
+ @view_3D = View3D.new({ r_ang_ax: 1 }.merge(options))
46
+ super
48
47
  axes.add_axis :ser_axis, SerAxis
49
48
  end
50
49
 
51
-
52
50
  # @see gapDepth
53
51
  def gap_depth=(v)
54
52
  RegexValidator.validate "Line3DChart.gapWidth", GAP_AMOUNT_PERCENT, v
55
- @gap_depth=(v)
53
+ @gap_depth = v
56
54
  end
57
55
  alias :gapDepth= :gap_depth=
58
56
 
59
- # Serializes the object
60
- # @param [String] str
61
- # @return [String]
62
- def to_xml_string(str = '')
63
- super(str) do
64
- str << ('<c:gapDepth val="' << @gap_depth.to_s << '"/>') unless @gap_depth.nil?
65
- end
57
+ # Serializes the object
58
+ # @param [String] str
59
+ # @return [String]
60
+ def to_xml_string(str = +'')
61
+ super do
62
+ str << '<c:gapDepth val="' << @gap_depth.to_s << '"/>' unless @gap_depth.nil?
66
63
  end
64
+ end
67
65
  end
68
66
  end
@@ -1,7 +1,7 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
4
- # The LineChart is a two dimentional line chart (who would have guessed?) that you can add to your worksheet.
3
+ module Axlsx
4
+ # The LineChart 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 LineChart < 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 = LineSeries
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 LineSeries 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 LineSeries < 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,10 +1,10 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # The Marker class defines a point in the worksheet that drawing anchors attach to.
4
5
  # @note The recommended way to manage markers is Worksheet#add_chart Markers are created for a two cell anchor based on the :start and :end options.
5
6
  # @see Worksheet#add_chart
6
7
  class Marker
7
-
8
8
  include Axlsx::OptionsParser
9
9
 
10
10
  # Creates a new Marker object
@@ -12,7 +12,7 @@ module Axlsx
12
12
  # @option options [Integer] colOff
13
13
  # @option options [Integer] row
14
14
  # @option options [Integer] rowOff
15
- def initialize(options={})
15
+ def initialize(options = {})
16
16
  @col, @colOff, @row, @rowOff = 0, 0, 0, 0
17
17
  parse_options options
18
18
  end
@@ -33,21 +33,36 @@ module Axlsx
33
33
  # @return [Integer]
34
34
  attr_reader :rowOff
35
35
 
36
- # @see col
37
- def col=(v) Axlsx::validate_unsigned_int v; @col = v end
36
+ # @see col
37
+ def col=(v)
38
+ Axlsx.validate_unsigned_int v
39
+ @col = v
40
+ end
41
+
38
42
  # @see colOff
39
- def colOff=(v) Axlsx::validate_int v; @colOff = v end
43
+ def colOff=(v)
44
+ Axlsx.validate_int v
45
+ @colOff = v
46
+ end
47
+
40
48
  # @see row
41
- def row=(v) Axlsx::validate_unsigned_int v; @row = v end
49
+ def row=(v)
50
+ Axlsx.validate_unsigned_int v
51
+ @row = v
52
+ end
53
+
42
54
  # @see rowOff
43
- def rowOff=(v) Axlsx::validate_int v; @rowOff = v end
55
+ def rowOff=(v)
56
+ Axlsx.validate_int v
57
+ @rowOff = v
58
+ end
44
59
 
45
60
  # shortcut to set the column, row position for this marker
46
61
  # @param col the column for the marker, a Cell object or a string reference like "B7"
47
62
  # or an Array.
48
63
  # @param row the row of the marker. This is ignored if the col parameter is a Cell or
49
64
  # String or Array.
50
- def coord(col, row=0)
65
+ def coord(col, row = 0)
51
66
  coordinates = parse_coord_args(col, row)
52
67
  self.col = coordinates[0]
53
68
  self.row = coordinates[1]
@@ -56,18 +71,19 @@ module Axlsx
56
71
  # Serializes the object
57
72
  # @param [String] str
58
73
  # @return [String]
59
- def to_xml_string(str = '')
74
+ def to_xml_string(str = +'')
60
75
  [:col, :colOff, :row, :rowOff].each do |k|
61
- str << ('<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>')
76
+ str << '<xdr:' << k.to_s << '>' << send(k).to_s << '</xdr:' << k.to_s << '>'
62
77
  end
63
78
  end
79
+
64
80
  private
65
81
 
66
82
  # handles multiple inputs for setting the position of a marker
67
83
  # @see Chart#start_at
68
- def parse_coord_args(x, y=0)
84
+ def parse_coord_args(x, y = 0)
69
85
  if x.is_a?(String)
70
- x, y = *Axlsx::name_to_indices(x)
86
+ x, y = *Axlsx.name_to_indices(x)
71
87
  end
72
88
  if x.is_a?(Cell)
73
89
  x, y = *x.pos
@@ -77,8 +93,5 @@ module Axlsx
77
93
  end
78
94
  [x, y]
79
95
  end
80
-
81
-
82
96
  end
83
-
84
97
  end
@@ -1,16 +1,15 @@
1
- # -*- coding: utf-8 -*-
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
4
- #This class specifies data for a particular data point. It is used for both numCache and numLit object
3
+ module Axlsx
4
+ # This class specifies data for a particular data point. It is used for both numCache and numLit object
5
5
  class NumData
6
-
7
6
  include Axlsx::OptionsParser
8
7
 
9
8
  # creates a new NumVal object
10
9
  # @option options [String] formatCode
11
10
  # @option options [Array] :data
12
11
  # @see StrData
13
- def initialize(options={})
12
+ def initialize(options = {})
14
13
  @format_code = "General"
15
14
  @pt = SimpleTypedList.new NumVal
16
15
  parse_options options
@@ -22,31 +21,29 @@ module Axlsx
22
21
 
23
22
  # Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types.
24
23
  # @param [Array] values An array of cells or values.
25
- def data=(values=[])
24
+ def data=(values = [])
26
25
  @tag_name = values.first.is_a?(Cell) ? :numCache : :numLit
27
26
  values.each do |value|
28
27
  value = value.is_formula? ? 0 : value.value if value.is_a?(Cell)
29
- @pt << NumVal.new(:v => value)
28
+ @pt << NumVal.new(v: value)
30
29
  end
31
30
  end
32
31
 
33
32
  # @see format_code
34
- def format_code=(v='General')
35
- Axlsx::validate_string(v)
33
+ def format_code=(v = 'General')
34
+ Axlsx.validate_string(v)
36
35
  @format_code = v
37
36
  end
38
37
 
39
38
  # serialize the object
40
- def to_xml_string(str = "")
41
- str << ('<c:' << @tag_name.to_s << '>')
42
- str << ('<c:formatCode>' << format_code.to_s << '</c:formatCode>')
43
- str << ('<c:ptCount val="' << @pt.size.to_s << '"/>')
39
+ def to_xml_string(str = +'')
40
+ str << '<c:' << @tag_name.to_s << '>'
41
+ str << '<c:formatCode>' << format_code.to_s << '</c:formatCode>'
42
+ str << '<c:ptCount val="' << @pt.size.to_s << '"/>'
44
43
  @pt.each_with_index do |num_val, index|
45
44
  num_val.to_xml_string index, str
46
45
  end
47
- str << ('</c:' << @tag_name.to_s << '>')
46
+ str << '</c:' << @tag_name.to_s << '>'
48
47
  end
49
-
50
48
  end
51
-
52
49
  end
@@ -1,14 +1,14 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A numeric data source for use by charts.
4
5
  class NumDataSource
5
-
6
6
  include Axlsx::OptionsParser
7
7
 
8
8
  # creates a new NumDataSource object
9
9
  # @option options [Array] data An array of Cells or Numeric objects
10
10
  # @option options [Symbol] tag_name see tag_name
11
- def initialize(options={})
11
+ def initialize(options = {})
12
12
  # override these three in child classes
13
13
  @data_type ||= NumData
14
14
  @tag_name ||= :val
@@ -17,12 +17,11 @@ module Axlsx
17
17
  @f = nil
18
18
  @data = @data_type.new(options)
19
19
  if options[:data] && options[:data].first.is_a?(Cell)
20
- @f = Axlsx::cell_range(options[:data])
20
+ @f = Axlsx.cell_range(options[:data])
21
21
  end
22
22
  parse_options options
23
23
  end
24
24
 
25
-
26
25
  # The tag name to use when serializing this data source.
27
26
  # Only items defined in allowed_tag_names are allowed
28
27
  # @return [Symbol]
@@ -36,7 +35,7 @@ module Axlsx
36
35
  [:yVal, :val, :bubbleSize]
37
36
  end
38
37
 
39
- # sets the tag name for this data source
38
+ # sets the tag name for this data source
40
39
  # @param [Symbol] v One of the allowed_tag_names
41
40
  def tag_name=(v)
42
41
  Axlsx::RestrictionValidator.validate "#{self.class.name}.tag_name", self.class.allowed_tag_names, v
@@ -45,18 +44,17 @@ module Axlsx
45
44
 
46
45
  # serialize the object
47
46
  # @param [String] str
48
- def to_xml_string(str="")
49
- str << ('<c:' << tag_name.to_s << '>')
47
+ def to_xml_string(str = +'')
48
+ str << '<c:' << tag_name.to_s << '>'
50
49
  if @f
51
- str << ('<c:' << @ref_tag_name.to_s << '>')
52
- str << ('<c:f>' << @f.to_s << '</c:f>')
50
+ str << '<c:' << @ref_tag_name.to_s << '>'
51
+ str << '<c:f>' << @f.to_s << '</c:f>'
53
52
  end
54
53
  @data.to_xml_string str
55
54
  if @f
56
- str << ('</c:' << @ref_tag_name.to_s << '>')
55
+ str << '</c:' << @ref_tag_name.to_s << '>'
57
56
  end
58
- str << ('</c:' << tag_name.to_s << '>')
57
+ str << '</c:' << tag_name.to_s << '>'
59
58
  end
60
59
  end
61
60
  end
62
-
@@ -1,9 +1,8 @@
1
- # -*- coding: utf-8 -*-
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
4
- #This class specifies data for a particular data point.
3
+ module Axlsx
4
+ # This class specifies data for a particular data point.
5
5
  class NumVal < StrVal
6
-
7
6
  # A string representing the format code to apply.
8
7
  # For more information see see the SpreadsheetML numFmt element's (§18.8.30) formatCode attribute.
9
8
  # @return [String]
@@ -12,22 +11,22 @@ module Axlsx
12
11
  # creates a new NumVal object
13
12
  # @option options [String] formatCode
14
13
  # @option options [Integer] v
15
- def initialize(options={})
14
+ def initialize(options = {})
16
15
  @format_code = "General"
17
- super(options)
16
+ super
18
17
  end
19
18
 
20
19
  # @see format_code
21
20
  def format_code=(v)
22
- Axlsx::validate_string(v)
21
+ Axlsx.validate_string(v)
23
22
  @format_code = v
24
23
  end
25
24
 
26
25
  # serialize the object
27
- def to_xml_string(idx, str = "")
28
- Axlsx::validate_unsigned_int(idx)
29
- if !v.to_s.empty?
30
- str << ('<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>')
26
+ def to_xml_string(idx, str = +'')
27
+ Axlsx.validate_unsigned_int(idx)
28
+ unless v.to_s.empty?
29
+ str << '<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>'
31
30
  end
32
31
  end
33
32
  end