caxlsx 3.3.0 → 4.0.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 (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +25 -7
  4. data/Rakefile +7 -6
  5. data/lib/axlsx/content_type/abstract_content_type.rb +11 -9
  6. data/lib/axlsx/content_type/content_type.rb +7 -9
  7. data/lib/axlsx/content_type/default.rb +4 -6
  8. data/lib/axlsx/content_type/override.rb +3 -5
  9. data/lib/axlsx/doc_props/app.rb +27 -30
  10. data/lib/axlsx/doc_props/core.rb +9 -12
  11. data/lib/axlsx/drawing/area_chart.rb +13 -14
  12. data/lib/axlsx/drawing/area_series.rb +13 -14
  13. data/lib/axlsx/drawing/ax_data_source.rb +3 -6
  14. data/lib/axlsx/drawing/axes.rb +10 -9
  15. data/lib/axlsx/drawing/axis.rb +27 -30
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +17 -18
  17. data/lib/axlsx/drawing/bar_chart.rb +16 -17
  18. data/lib/axlsx/drawing/bar_series.rb +9 -13
  19. data/lib/axlsx/drawing/bubble_chart.rb +8 -9
  20. data/lib/axlsx/drawing/bubble_series.rb +9 -10
  21. data/lib/axlsx/drawing/cat_axis.rb +14 -17
  22. data/lib/axlsx/drawing/chart.rb +25 -28
  23. data/lib/axlsx/drawing/d_lbls.rb +29 -26
  24. data/lib/axlsx/drawing/drawing.rb +60 -62
  25. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  26. data/lib/axlsx/drawing/hyperlink.rb +12 -13
  27. data/lib/axlsx/drawing/line_3D_chart.rb +13 -15
  28. data/lib/axlsx/drawing/line_chart.rb +13 -14
  29. data/lib/axlsx/drawing/line_series.rb +13 -14
  30. data/lib/axlsx/drawing/marker.rb +14 -16
  31. data/lib/axlsx/drawing/num_data.rb +13 -16
  32. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  33. data/lib/axlsx/drawing/num_val.rb +9 -10
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +10 -10
  35. data/lib/axlsx/drawing/pic.rb +57 -22
  36. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +6 -9
  38. data/lib/axlsx/drawing/pie_series.rb +9 -12
  39. data/lib/axlsx/drawing/scaling.rb +9 -10
  40. data/lib/axlsx/drawing/scatter_chart.rb +9 -10
  41. data/lib/axlsx/drawing/scatter_series.rb +15 -16
  42. data/lib/axlsx/drawing/ser_axis.rb +9 -11
  43. data/lib/axlsx/drawing/series.rb +8 -8
  44. data/lib/axlsx/drawing/series_title.rb +6 -6
  45. data/lib/axlsx/drawing/str_data.rb +10 -13
  46. data/lib/axlsx/drawing/str_val.rb +8 -9
  47. data/lib/axlsx/drawing/title.rb +23 -27
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +8 -8
  49. data/lib/axlsx/drawing/val_axis.rb +5 -6
  50. data/lib/axlsx/drawing/view_3D.rb +32 -30
  51. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  52. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  53. data/lib/axlsx/package.rb +81 -79
  54. data/lib/axlsx/rels/relationship.rb +30 -28
  55. data/lib/axlsx/rels/relationships.rb +7 -8
  56. data/lib/axlsx/stylesheet/border.rb +7 -8
  57. data/lib/axlsx/stylesheet/border_pr.rb +8 -8
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +14 -20
  59. data/lib/axlsx/stylesheet/cell_protection.rb +6 -7
  60. data/lib/axlsx/stylesheet/cell_style.rb +12 -14
  61. data/lib/axlsx/stylesheet/color.rb +15 -12
  62. data/lib/axlsx/stylesheet/dxf.rb +7 -9
  63. data/lib/axlsx/stylesheet/fill.rb +3 -5
  64. data/lib/axlsx/stylesheet/font.rb +24 -21
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +9 -9
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +7 -6
  67. data/lib/axlsx/stylesheet/num_fmt.rb +9 -14
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +8 -8
  69. data/lib/axlsx/stylesheet/styles.rb +104 -98
  70. data/lib/axlsx/stylesheet/table_style.rb +8 -9
  71. data/lib/axlsx/stylesheet/table_style_element.rb +7 -8
  72. data/lib/axlsx/stylesheet/table_styles.rb +8 -10
  73. data/lib/axlsx/stylesheet/xf.rb +21 -22
  74. data/lib/axlsx/util/accessors.rb +6 -6
  75. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  76. data/lib/axlsx/util/constants.rb +119 -108
  77. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  78. data/lib/axlsx/util/options_parser.rb +4 -3
  79. data/lib/axlsx/util/serialized_attributes.rb +45 -21
  80. data/lib/axlsx/util/simple_typed_list.rb +58 -57
  81. data/lib/axlsx/util/storage.rb +38 -41
  82. data/lib/axlsx/util/validators.rb +107 -44
  83. data/lib/axlsx/util/zip_command.rb +10 -12
  84. data/lib/axlsx/version.rb +3 -2
  85. data/lib/axlsx/workbook/defined_name.rb +11 -8
  86. data/lib/axlsx/workbook/defined_names.rb +4 -3
  87. data/lib/axlsx/workbook/shared_strings_table.rb +10 -11
  88. data/lib/axlsx/workbook/workbook.rb +121 -114
  89. data/lib/axlsx/workbook/workbook_view.rb +8 -11
  90. data/lib/axlsx/workbook/workbook_views.rb +4 -4
  91. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +72 -14
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -7
  93. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +24 -21
  94. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  95. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  96. data/lib/axlsx/workbook/worksheet/border_creator.rb +30 -25
  97. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  98. data/lib/axlsx/workbook/worksheet/cell.rb +92 -65
  99. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +32 -28
  100. data/lib/axlsx/workbook/worksheet/cfvo.rb +7 -5
  101. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  102. data/lib/axlsx/workbook/worksheet/col.rb +9 -10
  103. data/lib/axlsx/workbook/worksheet/col_breaks.rb +8 -7
  104. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  105. data/lib/axlsx/workbook/worksheet/cols.rb +9 -7
  106. data/lib/axlsx/workbook/worksheet/comment.rb +12 -11
  107. data/lib/axlsx/workbook/worksheet/comments.rb +10 -12
  108. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +12 -8
  109. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +19 -21
  110. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +5 -5
  111. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  112. data/lib/axlsx/workbook/worksheet/data_validation.rb +34 -33
  113. data/lib/axlsx/workbook/worksheet/data_validations.rb +5 -6
  114. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/dimension.rb +9 -6
  116. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -3
  117. data/lib/axlsx/workbook/worksheet/icon_set.rb +24 -8
  118. data/lib/axlsx/workbook/worksheet/merged_cells.rb +10 -10
  119. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -3
  120. data/lib/axlsx/workbook/worksheet/page_margins.rb +17 -12
  121. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -4
  122. data/lib/axlsx/workbook/worksheet/page_setup.rb +128 -129
  123. data/lib/axlsx/workbook/worksheet/pane.rb +27 -26
  124. data/lib/axlsx/workbook/worksheet/pivot_table.rb +23 -25
  125. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  126. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +5 -4
  127. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -2
  128. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  129. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +12 -10
  130. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  131. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +35 -17
  132. data/lib/axlsx/workbook/worksheet/row.rb +30 -22
  133. data/lib/axlsx/workbook/worksheet/row_breaks.rb +8 -7
  134. data/lib/axlsx/workbook/worksheet/selection.rb +16 -16
  135. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +10 -7
  136. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  137. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  138. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +11 -7
  139. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +21 -20
  140. data/lib/axlsx/workbook/worksheet/sheet_view.rb +48 -53
  141. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  142. data/lib/axlsx/workbook/worksheet/table_style_info.rb +6 -5
  143. data/lib/axlsx/workbook/worksheet/tables.rb +7 -5
  144. data/lib/axlsx/workbook/worksheet/worksheet.rb +92 -63
  145. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +10 -8
  146. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  147. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +9 -8
  148. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +7 -5
  149. data/lib/axlsx.rb +75 -47
  150. data/lib/caxlsx.rb +3 -2
  151. metadata +50 -44
@@ -1,6 +1,6 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # The LineChart is a two dimentional 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.
@@ -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,7 +44,7 @@ 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
50
  super(frame, options)
@@ -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 = '')
77
+ def to_xml_string(str = +'')
79
78
  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 << '"/>')
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
43
  super(chart, options)
44
- @labels = AxDataSource.new(:data => options[:labels]) unless options[:labels].nil?
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 = '')
74
+ def to_xml_string(str = +'')
75
75
  super(str) 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,12 +89,12 @@ 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
 
@@ -105,6 +105,5 @@ module Axlsx
105
105
 
106
106
  # assigns the labels for this series
107
107
  def labels=(v) DataTypeValidator.validate "Series.labels", [AxDataSource], v; @labels = v; end
108
-
109
108
  end
110
109
  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,21 @@ 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) Axlsx.validate_unsigned_int v; @col = v end
38
38
  # @see colOff
39
- def colOff=(v) Axlsx::validate_int v; @colOff = v end
39
+ def colOff=(v) Axlsx.validate_int v; @colOff = v end
40
40
  # @see row
41
- def row=(v) Axlsx::validate_unsigned_int v; @row = v end
41
+ def row=(v) Axlsx.validate_unsigned_int v; @row = v end
42
42
  # @see rowOff
43
- def rowOff=(v) Axlsx::validate_int v; @rowOff = v end
43
+ def rowOff=(v) Axlsx.validate_int v; @rowOff = v end
44
44
 
45
45
  # shortcut to set the column, row position for this marker
46
46
  # @param col the column for the marker, a Cell object or a string reference like "B7"
47
47
  # or an Array.
48
48
  # @param row the row of the marker. This is ignored if the col parameter is a Cell or
49
49
  # String or Array.
50
- def coord(col, row=0)
50
+ def coord(col, row = 0)
51
51
  coordinates = parse_coord_args(col, row)
52
52
  self.col = coordinates[0]
53
53
  self.row = coordinates[1]
@@ -56,18 +56,19 @@ module Axlsx
56
56
  # Serializes the object
57
57
  # @param [String] str
58
58
  # @return [String]
59
- def to_xml_string(str = '')
59
+ def to_xml_string(str = +'')
60
60
  [:col, :colOff, :row, :rowOff].each do |k|
61
- str << ('<xdr:' << k.to_s << '>' << self.send(k).to_s << '</xdr:' << k.to_s << '>')
61
+ str << '<xdr:' << k.to_s << '>' << send(k).to_s << '</xdr:' << k.to_s << '>'
62
62
  end
63
63
  end
64
+
64
65
  private
65
66
 
66
67
  # handles multiple inputs for setting the position of a marker
67
68
  # @see Chart#start_at
68
- def parse_coord_args(x, y=0)
69
+ def parse_coord_args(x, y = 0)
69
70
  if x.is_a?(String)
70
- x, y = *Axlsx::name_to_indices(x)
71
+ x, y = *Axlsx.name_to_indices(x)
71
72
  end
72
73
  if x.is_a?(Cell)
73
74
  x, y = *x.pos
@@ -77,8 +78,5 @@ module Axlsx
77
78
  end
78
79
  [x, y]
79
80
  end
80
-
81
-
82
81
  end
83
-
84
82
  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
16
  super(options)
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
@@ -1,11 +1,11 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # This class details a single cell anchor for drawings.
4
5
  # @note The recommended way to manage drawings, images and charts is Worksheet#add_chart or Worksheet#add_image.
5
6
  # @see Worksheet#add_chart
6
7
  # @see Worksheet#add_image
7
8
  class OneCellAnchor
8
-
9
9
  include Axlsx::OptionsParser
10
10
 
11
11
  # Creates a new OneCellAnchor object and an Pic associated with it.
@@ -16,7 +16,7 @@ module Axlsx
16
16
  # @option options [String] image_src the file location of the image you will render
17
17
  # @option options [String] name the name attribute for the rendered image
18
18
  # @option options [String] descr the description of the image rendered
19
- def initialize(drawing, options={})
19
+ def initialize(drawing, options = {})
20
20
  @drawing = drawing
21
21
  @width = 0
22
22
  @height = 0
@@ -54,15 +54,16 @@ module Axlsx
54
54
  # We just 'figure it out' for you.
55
55
  # @param [Array, String, Cell, Integer] x Accepts many inputs for defining the starting position of the cell.
56
56
  # @param [Integer] y When x is an integer, this value is used for the row index at which the anchor starts.
57
- def start_at(x, y=0)
57
+ def start_at(x, y = 0)
58
58
  from.coord x, y
59
59
  end
60
+
60
61
  #
61
62
  # @see height
62
- def height=(v) Axlsx::validate_unsigned_int(v); @height = v; end
63
+ def height=(v) Axlsx.validate_unsigned_int(v); @height = v; end
63
64
 
64
65
  # @see width
65
- def width=(v) Axlsx::validate_unsigned_int(v); @width = v; end
66
+ def width=(v) Axlsx.validate_unsigned_int(v); @width = v; end
66
67
 
67
68
  # The index of this anchor in the drawing
68
69
  # @return [Integer]
@@ -73,12 +74,12 @@ module Axlsx
73
74
  # Serializes the object
74
75
  # @param [String] str
75
76
  # @return [String]
76
- def to_xml_string(str = '')
77
+ def to_xml_string(str = +'')
77
78
  str << '<xdr:oneCellAnchor>'
78
79
  str << '<xdr:from>'
79
80
  from.to_xml_string(str)
80
81
  str << '</xdr:from>'
81
- str << ('<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>')
82
+ str << '<xdr:ext cx="' << ext[:cx].to_s << '" cy="' << ext[:cy].to_s << '"/>'
82
83
  @object.to_xml_string(str)
83
84
  str << '<xdr:clientData/>'
84
85
  str << '</xdr:oneCellAnchor>'
@@ -92,8 +93,7 @@ module Axlsx
92
93
  def ext
93
94
  cy = @height * 914400 / 96
94
95
  cx = @width * 914400 / 96
95
- {:cy=>cy, :cx=>cx}
96
+ { cy: cy, cx: cx }
96
97
  end
97
-
98
98
  end
99
99
  end