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,13 +1,12 @@
1
- # encoding: UTF-8
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
3
+ module Axlsx
4
4
  # A ScatterSeries defines the x and y position of data in the chart
5
5
  # @note The recommended way to manage series is to use Chart#add_series
6
6
  # @see Worksheet#add_chart
7
7
  # @see Chart#add_series
8
8
  # @see examples/example.rb
9
9
  class ScatterSeries < Series
10
-
11
10
  # The x data for this series.
12
11
  # @return [NamedAxisData]
13
12
  attr_reader :xData
@@ -37,23 +36,23 @@ module Axlsx
37
36
  attr_reader :marker_symbol
38
37
 
39
38
  # Creates a new ScatterSeries
40
- def initialize(chart, options={})
39
+ def initialize(chart, options = {})
41
40
  @xData, @yData = nil
42
41
  if options[:smooth].nil?
43
42
  # If caller hasn't specified smoothing or not, turn smoothing on or off based on scatter style
44
43
  @smooth = [:smooth, :smoothMarker].include?(chart.scatter_style)
45
44
  else
46
45
  # Set smoothing according to the option provided
47
- Axlsx::validate_boolean(options[:smooth])
46
+ Axlsx.validate_boolean(options[:smooth])
48
47
  @smooth = options[:smooth]
49
48
  end
50
49
  @ln_width = options[:ln_width] unless options[:ln_width].nil?
51
50
  @show_marker = [:lineMarker, :marker, :smoothMarker].include?(chart.scatter_style)
52
51
  @marker_symbol = :default
53
52
 
54
- super(chart, options)
55
- @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
56
- @yData = NumDataSource.new({:tag_name => :yVal, :data => options[:yData]}) unless options[:yData].nil?
53
+ super
54
+ @xData = AxDataSource.new(tag_name: :xVal, data: options[:xData]) unless options[:xData].nil?
55
+ @yData = NumDataSource.new({ tag_name: :yVal, data: options[:yData] }) unless options[:yData].nil?
57
56
  end
58
57
 
59
58
  # @see color
@@ -63,7 +62,7 @@ module Axlsx
63
62
 
64
63
  # @see smooth
65
64
  def smooth=(v)
66
- Axlsx::validate_boolean(v)
65
+ Axlsx.validate_boolean(v)
67
66
  @smooth = v
68
67
  end
69
68
 
@@ -74,29 +73,29 @@ module Axlsx
74
73
 
75
74
  # @see marker_symbol
76
75
  def marker_symbol=(v)
77
- Axlsx::validate_marker_symbol(v)
76
+ Axlsx.validate_marker_symbol(v)
78
77
  @marker_symbol = v
79
78
  end
80
79
 
81
80
  # Serializes the object
82
81
  # @param [String] str
83
82
  # @return [String]
84
- def to_xml_string(str = '')
85
- super(str) do
83
+ def to_xml_string(str = +'')
84
+ super do
86
85
  # needs to override the super color here to push in ln/and something else!
87
86
  if color
88
87
  str << '<c:spPr><a:solidFill>'
89
- str << ('<a:srgbClr val="' << color << '"/>')
88
+ str << '<a:srgbClr val="' << color << '"/>'
90
89
  str << '</a:solidFill>'
91
90
  str << '<a:ln><a:solidFill>'
92
- str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
91
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
93
92
  str << '</c:spPr>'
94
93
  str << '<c:marker>'
95
94
  str << '<c:spPr><a:solidFill>'
96
- str << ('<a:srgbClr val="' << color << '"/>')
95
+ str << '<a:srgbClr val="' << color << '"/>'
97
96
  str << '</a:solidFill>'
98
97
  str << '<a:ln><a:solidFill>'
99
- str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
98
+ str << '<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>'
100
99
  str << '</c:spPr>'
101
100
  str << marker_symbol_xml
102
101
  str << '</c:marker>'
@@ -111,7 +110,7 @@ module Axlsx
111
110
  end
112
111
  @xData.to_xml_string(str) unless @xData.nil?
113
112
  @yData.to_xml_string(str) unless @yData.nil?
114
- str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
113
+ str << '<c:smooth val="' << (smooth ? '1' : '0') << '"/>'
115
114
  end
116
115
  str
117
116
  end
@@ -122,7 +121,7 @@ module Axlsx
122
121
  if !@show_marker
123
122
  '<c:symbol val="none"/>'
124
123
  elsif @marker_symbol != :default
125
- '<c:symbol val="' + @marker_symbol.to_s + '"/>'
124
+ +'<c:symbol val="' << @marker_symbol.to_s << '"/>'
126
125
  end.to_s
127
126
  end
128
127
  end
@@ -1,45 +1,48 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
- #A SerAxis object defines a series axis
4
+ # A SerAxis object defines a series axis
4
5
  class SerAxis < Axis
5
-
6
- # The number of tick lables to skip between labels
7
- # @return [Integer]
6
+ # The number of tick labels to skip between labels
7
+ # @return [Integer, nil]
8
8
  attr_reader :tick_lbl_skip
9
9
  alias :tickLblSkip :tick_lbl_skip
10
10
 
11
11
  # The number of tickmarks to be skipped before the next one is rendered.
12
- # @return [Boolean]
12
+ # @return [Integer, nil]
13
13
  attr_reader :tick_mark_skip
14
14
  alias :tickMarkSkip :tick_mark_skip
15
15
 
16
16
  # Creates a new SerAxis object
17
- # @option options [Integer] tick_lbl_skip
18
- # @option options [Integer] tick_mark_skip
19
- def initialize(options={})
20
- @tick_lbl_skip, @tick_mark_skip = 1, 1
21
- super(options)
17
+ # @option options [Integer, nil] tick_lbl_skip
18
+ # @option options [Integer, nil] tick_mark_skip
19
+ def initialize(options = {})
20
+ super
22
21
  end
23
22
 
24
23
  # @see tickLblSkip
25
- def tick_lbl_skip=(v) Axlsx::validate_unsigned_int(v); @tick_lbl_skip = v; end
24
+ def tick_lbl_skip=(v)
25
+ Axlsx.validate_unsigned_int(v) unless v.nil?
26
+ @tick_lbl_skip = v
27
+ end
26
28
  alias :tickLblSkip= :tick_lbl_skip=
27
29
 
28
30
  # @see tickMarkSkip
29
- def tick_mark_skip=(v) Axlsx::validate_unsigned_int(v); @tick_mark_skip = v; end
31
+ def tick_mark_skip=(v)
32
+ Axlsx.validate_unsigned_int(v) unless v.nil?
33
+ @tick_mark_skip = v
34
+ end
30
35
  alias :tickMarkSkip= :tick_mark_skip=
31
36
 
32
37
  # Serializes the object
33
38
  # @param [String] str
34
39
  # @return [String]
35
- def to_xml_string(str = '')
40
+ def to_xml_string(str = +'')
36
41
  str << '<c:serAx>'
37
- super(str)
38
- str << ('<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>') unless @tick_lbl_skip.nil?
39
- str << ('<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>') unless @tick_mark_skip.nil?
42
+ super
43
+ str << '<c:tickLblSkip val="' << @tick_lbl_skip.to_s << '"/>' unless @tick_lbl_skip.nil?
44
+ str << '<c:tickMarkSkip val="' << @tick_mark_skip.to_s << '"/>' unless @tick_mark_skip.nil?
40
45
  str << '</c:serAx>'
41
46
  end
42
47
  end
43
-
44
-
45
48
  end
@@ -1,11 +1,11 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A Series defines the common series attributes and is the super class for all concrete series types.
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 Series
8
-
9
9
  include Axlsx::OptionsParser
10
10
 
11
11
  # The chart that owns this series
@@ -20,7 +20,7 @@ module Axlsx
20
20
  # @param [Chart] chart
21
21
  # @option options [Integer] order
22
22
  # @option options [String] title
23
- def initialize(chart, options={})
23
+ def initialize(chart, options = {})
24
24
  @order = nil
25
25
  self.chart = chart
26
26
  @chart.series << self
@@ -40,7 +40,10 @@ module Axlsx
40
40
  end
41
41
 
42
42
  # @see order
43
- def order=(v) Axlsx::validate_unsigned_int(v); @order = v; end
43
+ def order=(v)
44
+ Axlsx.validate_unsigned_int(v)
45
+ @order = v
46
+ end
44
47
 
45
48
  # @see title
46
49
  def title=(v)
@@ -52,15 +55,18 @@ module Axlsx
52
55
  private
53
56
 
54
57
  # assigns the chart for this series
55
- def chart=(v) DataTypeValidator.validate "Series.chart", Chart, v; @chart = v; end
58
+ def chart=(v)
59
+ DataTypeValidator.validate "Series.chart", Chart, v
60
+ @chart = v
61
+ end
56
62
 
57
63
  # Serializes the object
58
64
  # @param [String] str
59
65
  # @return [String]
60
- def to_xml_string(str = '')
66
+ def to_xml_string(str = +'')
61
67
  str << '<c:ser>'
62
- str << ('<c:idx val="' << index.to_s << '"/>')
63
- str << ('<c:order val="' << (order || index).to_s << '"/>')
68
+ str << '<c:idx val="' << index.to_s << '"/>'
69
+ str << '<c:order val="' << (order || index).to_s << '"/>'
64
70
  title.to_xml_string(str) unless title.nil?
65
71
  yield if block_given?
66
72
  str << '</c:ser>'
@@ -1,21 +1,21 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A series title is a Title with a slightly different serialization than chart titles.
4
5
  class SeriesTitle < Title
5
-
6
6
  # Serializes the object
7
7
  # @param [String] str
8
8
  # @return [String]
9
- def to_xml_string(str = '')
10
- clean_value = Axlsx::trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@text.to_s))
9
+ def to_xml_string(str = +'')
10
+ clean_value = Axlsx.trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@text.to_s))
11
11
 
12
12
  str << '<c:tx>'
13
13
  str << '<c:strRef>'
14
- str << ('<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>')
14
+ str << '<c:f>' << Axlsx.cell_range([@cell]) << '</c:f>'
15
15
  str << '<c:strCache>'
16
16
  str << '<c:ptCount val="1"/>'
17
17
  str << '<c:pt idx="0">'
18
- str << ('<c:v>' << clean_value << '</c:v>')
18
+ str << '<c:v>' << clean_value << '</c:v>'
19
19
  str << '</c:pt>'
20
20
  str << '</c:strCache>'
21
21
  str << '</c:strRef>'
@@ -1,16 +1,15 @@
1
- # -*- coding: utf-8 -*-
2
- module Axlsx
1
+ # frozen_string_literal: true
3
2
 
4
- #This specifies the last string data used for a chart. (e.g. strLit and strCache)
3
+ module Axlsx
4
+ # This specifies the last string data used for a chart. (e.g. strLit and strCache)
5
5
  # This class is extended for NumData to include the formatCode attribute required for numLit and numCache
6
6
  class StrData
7
-
8
7
  include Axlsx::OptionsParser
9
8
 
10
9
  # creates a new StrVal object
11
10
  # @option options [Array] :data
12
11
  # @option options [String] :tag_name
13
- def initialize(options={})
12
+ def initialize(options = {})
14
13
  @tag_prefix = :str
15
14
  @type = StrVal
16
15
  @pt = SimpleTypedList.new(@type)
@@ -19,24 +18,22 @@ module Axlsx
19
18
 
20
19
  # Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types.
21
20
  # @param [Array] values An array of cells or values.
22
- def data=(values=[])
21
+ def data=(values = [])
23
22
  @tag_name = values.first.is_a?(Cell) ? :strCache : :strLit
24
23
  values.each do |value|
25
24
  v = value.is_a?(Cell) ? value.value : value
26
- @pt << @type.new(:v => v)
25
+ @pt << @type.new(v: v)
27
26
  end
28
27
  end
29
28
 
30
29
  # serialize the object
31
- def to_xml_string(str = "")
32
- str << ('<c:' << @tag_name.to_s << '>')
33
- str << ('<c:ptCount val="' << @pt.size.to_s << '"/>')
30
+ def to_xml_string(str = +'')
31
+ str << '<c:' << @tag_name.to_s << '>'
32
+ str << '<c:ptCount val="' << @pt.size.to_s << '"/>'
34
33
  @pt.each_with_index do |value, index|
35
34
  value.to_xml_string index, str
36
35
  end
37
- str << ('</c:' << @tag_name.to_s << '>')
36
+ str << '</c:' << @tag_name.to_s << '>'
38
37
  end
39
-
40
38
  end
41
-
42
39
  end
@@ -1,14 +1,13 @@
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 StrVal
6
-
7
6
  include Axlsx::OptionsParser
8
7
 
9
8
  # creates a new StrVal object
10
9
  # @option options [String] v
11
- def initialize(options={})
10
+ def initialize(options = {})
12
11
  @v = ""
13
12
  @idx = 0
14
13
  parse_options options
@@ -24,10 +23,10 @@ module Axlsx
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 << '"><c:v>' << ::CGI.escapeHTML(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 << '"><c:v>' << ::CGI.escapeHTML(v.to_s) << '</c:v></c:pt>'
31
30
  end
32
31
  end
33
32
  end
@@ -1,8 +1,8 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # A Title stores information about the title of a chart
4
5
  class Title
5
-
6
6
  # The text to be shown. Setting this property directly with a string will remove the cell reference.
7
7
  # @return [String]
8
8
  attr_reader :text
@@ -17,14 +17,14 @@ module Axlsx
17
17
 
18
18
  # Creates a new Title object
19
19
  # @param [String, Cell] title The cell or string to be used for the chart's title
20
- def initialize(title="", title_size="")
20
+ def initialize(title = "", title_size = "")
21
21
  self.cell = title if title.is_a?(Cell)
22
22
  self.text = title.to_s unless title.is_a?(Cell)
23
- if title_size.to_s.empty?
24
- self.text_size = "1600"
25
- else
26
- self.text_size = title_size.to_s
27
- end
23
+ self.text_size = if title_size.to_s.empty?
24
+ "1600"
25
+ else
26
+ title_size.to_s
27
+ end
28
28
  end
29
29
 
30
30
  # @see text
@@ -32,7 +32,6 @@ module Axlsx
32
32
  DataTypeValidator.validate 'Title.text', String, v
33
33
  @text = v
34
34
  @cell = nil
35
- v
36
35
  end
37
36
 
38
37
  # @see text_size
@@ -40,7 +39,6 @@ module Axlsx
40
39
  DataTypeValidator.validate 'Title.text_size', String, v
41
40
  @text_size = v
42
41
  @cell = nil
43
- v
44
42
  end
45
43
 
46
44
  # @see cell
@@ -48,7 +46,6 @@ module Axlsx
48
46
  DataTypeValidator.validate 'Title.text', Cell, v
49
47
  @cell = v
50
48
  @text = v.value.to_s
51
- v
52
49
  end
53
50
 
54
51
  # Check if the title is empty.
@@ -62,38 +59,38 @@ module Axlsx
62
59
  end
63
60
 
64
61
  # Not implemented at this time.
65
- #def layout=(v) DataTypeValidator.validate 'Title.layout', Layout, v; @layout = v; end
66
- #def overlay=(v) Axlsx::validate_boolean v; @overlay=v; end
67
- #def spPr=(v) DataTypeValidator.validate 'Title.spPr', SpPr, v; @spPr = v; end
62
+ # def layout=(v) DataTypeValidator.validate 'Title.layout', Layout, v; @layout = v; end
63
+ # def overlay=(v) Axlsx::validate_boolean v; @overlay=v; end
64
+ # def spPr=(v) DataTypeValidator.validate 'Title.spPr', SpPr, v; @spPr = v; end
68
65
 
69
66
  # Serializes the object
70
67
  # @param [String] str
71
68
  # @return [String]
72
- def to_xml_string(str = '')
69
+ def to_xml_string(str = +'')
73
70
  str << '<c:title>'
74
71
  unless empty?
75
- clean_value = Axlsx::trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx::sanitize(@text.to_s))
72
+ clean_value = Axlsx.trust_input ? @text.to_s : ::CGI.escapeHTML(Axlsx.sanitize(@text.to_s))
76
73
  str << '<c:tx>'
77
74
  if @cell.is_a?(Cell)
78
75
  str << '<c:strRef>'
79
- str << ('<c:f>' << Axlsx::cell_range([@cell]) << '</c:f>')
76
+ str << '<c:f>' << Axlsx.cell_range([@cell]) << '</c:f>'
80
77
  str << '<c:strCache>'
81
78
  str << '<c:ptCount val="1"/>'
82
79
  str << '<c:pt idx="0">'
83
- str << ('<c:v>' << clean_value << '</c:v>')
80
+ str << '<c:v>' << clean_value << '</c:v>'
84
81
  str << '</c:pt>'
85
82
  str << '</c:strCache>'
86
83
  str << '</c:strRef>'
87
84
  else
88
85
  str << '<c:rich>'
89
- str << '<a:bodyPr/>'
90
- str << '<a:lstStyle/>'
91
- str << '<a:p>'
92
- str << '<a:r>'
93
- str << ('<a:rPr sz="' << @text_size.to_s << '"/>')
94
- str << ('<a:t>' << clean_value << '</a:t>')
95
- str << '</a:r>'
96
- str << '</a:p>'
86
+ str << '<a:bodyPr/>'
87
+ str << '<a:lstStyle/>'
88
+ str << '<a:p>'
89
+ str << '<a:r>'
90
+ str << '<a:rPr sz="' << @text_size.to_s << '"/>'
91
+ str << '<a:t>' << clean_value << '</a:t>'
92
+ str << '</a:r>'
93
+ str << '</a:p>'
97
94
  str << '</c:rich>'
98
95
  end
99
96
  str << '</c:tx>'
@@ -102,6 +99,5 @@ module Axlsx
102
99
  str << '<c:overlay val="0"/>'
103
100
  str << '</c:title>'
104
101
  end
105
-
106
102
  end
107
103
  end
@@ -1,10 +1,10 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # This class details the anchor points for drawings.
4
5
  # @note The recommended way to manage drawings and charts is Worksheet#add_chart. Anchors are specified by the :start_at and :end_at options to that method.
5
6
  # @see Worksheet#add_chart
6
7
  class TwoCellAnchor
7
-
8
8
  include Axlsx::OptionsParser
9
9
 
10
10
  # A marker that defines the from cell anchor. The default from column and row are 0 and 0 respectively
@@ -32,14 +32,14 @@ module Axlsx
32
32
  # @param [Drawing] drawing
33
33
  # @option options [Array] :start_at the col, row to start at THIS IS DOCUMENTED BUT NOT IMPLEMENTED HERE!
34
34
  # @option options [Array] :end_at the col, row to end at
35
- def initialize(drawing, options={})
35
+ def initialize(drawing, options = {})
36
36
  @drawing = drawing
37
37
  drawing.anchors << self
38
- @from, @to = Marker.new, Marker.new(:col => 5, :row=>10)
38
+ @from, @to = Marker.new, Marker.new(col: 5, row: 10)
39
39
  parse_options options
40
40
 
41
41
  # bit of a hack to work around the fact that the coords for start at and end at
42
- # are passed in as an array when specified in intialization options - however
42
+ # are passed in as an array when specified in initialization options - however
43
43
  start_at(*options[:start_at]) if options[:start_at]
44
44
  end_at(*options[:end_at]) if options[:end_at]
45
45
  end
@@ -48,7 +48,7 @@ module Axlsx
48
48
  # @note The recommended way to set the start position for graphical
49
49
  # objects is directly thru the object.
50
50
  # @see Chart#start_at
51
- def start_at(x, y=nil)
51
+ def start_at(x, y = nil)
52
52
  from.coord x, y
53
53
  end
54
54
 
@@ -56,7 +56,7 @@ module Axlsx
56
56
  # @note the recommended way to set the to position for graphical
57
57
  # objects is directly thru the object
58
58
  # @see Char#end_at
59
- def end_at(x, y=nil)
59
+ def end_at(x, y = nil)
60
60
  to.coord x, y
61
61
  end
62
62
 
@@ -68,7 +68,7 @@ module Axlsx
68
68
  end
69
69
 
70
70
  # Creates an image associated with this anchor.
71
- def add_pic(options={})
71
+ def add_pic(options = {})
72
72
  @object = Pic.new(self, options)
73
73
  end
74
74
 
@@ -81,7 +81,7 @@ module Axlsx
81
81
  # Serializes the object
82
82
  # @param [String] str
83
83
  # @return [String]
84
- def to_xml_string(str = '')
84
+ def to_xml_string(str = +'')
85
85
  str << '<xdr:twoCellAnchor>'
86
86
  str << '<xdr:from>'
87
87
  from.to_xml_string str
@@ -1,8 +1,8 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # the ValAxis class defines a chart value axis.
4
5
  class ValAxis < Axis
5
-
6
6
  # This element specifies how the value axis crosses the category axis.
7
7
  # must be one of [:between, :midCat]
8
8
  # @return [Symbol]
@@ -11,9 +11,9 @@ module Axlsx
11
11
 
12
12
  # Creates a new ValAxis object
13
13
  # @option options [Symbol] crosses_between
14
- def initialize(options={})
14
+ def initialize(options = {})
15
15
  self.cross_between = :between
16
- super(options)
16
+ super
17
17
  end
18
18
 
19
19
  # @see cross_between
@@ -26,12 +26,11 @@ module Axlsx
26
26
  # Serializes the object
27
27
  # @param [String] str
28
28
  # @return [String]
29
- def to_xml_string(str = '')
29
+ def to_xml_string(str = +'')
30
30
  str << '<c:valAx>'
31
- super(str)
32
- str << ('<c:crossBetween val="' << @cross_between.to_s << '"/>')
31
+ super
32
+ str << '<c:crossBetween val="' << @cross_between.to_s << '"/>'
33
33
  str << '</c:valAx>'
34
34
  end
35
-
36
35
  end
37
36
  end