caxlsx 3.4.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -1
  3. data/README.md +9 -11
  4. data/Rakefile +7 -5
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +12 -4
  7. data/lib/axlsx/content_type/content_type.rb +8 -6
  8. data/lib/axlsx/content_type/default.rb +7 -2
  9. data/lib/axlsx/content_type/override.rb +7 -2
  10. data/lib/axlsx/doc_props/app.rb +95 -26
  11. data/lib/axlsx/doc_props/core.rb +8 -6
  12. data/lib/axlsx/drawing/area_chart.rb +10 -8
  13. data/lib/axlsx/drawing/area_series.rb +20 -12
  14. data/lib/axlsx/drawing/ax_data_source.rb +2 -0
  15. data/lib/axlsx/drawing/axes.rb +6 -4
  16. data/lib/axlsx/drawing/axis.rb +42 -22
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -12
  18. data/lib/axlsx/drawing/bar_chart.rb +13 -11
  19. data/lib/axlsx/drawing/bar_series.rb +20 -9
  20. data/lib/axlsx/drawing/bubble_chart.rb +6 -4
  21. data/lib/axlsx/drawing/bubble_series.rb +8 -6
  22. data/lib/axlsx/drawing/cat_axis.rb +29 -12
  23. data/lib/axlsx/drawing/chart.rb +46 -20
  24. data/lib/axlsx/drawing/d_lbls.rb +10 -8
  25. data/lib/axlsx/drawing/drawing.rb +59 -56
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -4
  27. data/lib/axlsx/drawing/hyperlink.rb +19 -8
  28. data/lib/axlsx/drawing/line_3D_chart.rb +7 -5
  29. data/lib/axlsx/drawing/line_chart.rb +10 -8
  30. data/lib/axlsx/drawing/line_series.rb +20 -12
  31. data/lib/axlsx/drawing/marker.rb +24 -7
  32. data/lib/axlsx/drawing/num_data.rb +9 -7
  33. data/lib/axlsx/drawing/num_data_source.rb +9 -7
  34. data/lib/axlsx/drawing/num_val.rb +7 -5
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +13 -5
  36. data/lib/axlsx/drawing/pic.rb +26 -15
  37. data/lib/axlsx/drawing/picture_locking.rb +3 -1
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +6 -4
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +23 -9
  41. data/lib/axlsx/drawing/scaling.rb +25 -9
  42. data/lib/axlsx/drawing/scatter_chart.rb +7 -5
  43. data/lib/axlsx/drawing/scatter_series.rb +14 -12
  44. data/lib/axlsx/drawing/ser_axis.rb +13 -5
  45. data/lib/axlsx/drawing/series.rb +13 -5
  46. data/lib/axlsx/drawing/series_title.rb +6 -4
  47. data/lib/axlsx/drawing/str_data.rb +7 -5
  48. data/lib/axlsx/drawing/str_val.rb +6 -4
  49. data/lib/axlsx/drawing/title.rb +13 -14
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +4 -2
  51. data/lib/axlsx/drawing/val_axis.rb +4 -2
  52. data/lib/axlsx/drawing/view_3D.rb +16 -8
  53. data/lib/axlsx/drawing/vml_drawing.rb +18 -16
  54. data/lib/axlsx/drawing/vml_shape.rb +24 -22
  55. data/lib/axlsx/package.rb +73 -67
  56. data/lib/axlsx/rels/relationship.rb +21 -6
  57. data/lib/axlsx/rels/relationships.rb +6 -4
  58. data/lib/axlsx/stylesheet/border.rb +15 -4
  59. data/lib/axlsx/stylesheet/border_pr.rb +19 -6
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +41 -10
  61. data/lib/axlsx/stylesheet/cell_protection.rb +12 -3
  62. data/lib/axlsx/stylesheet/cell_style.rb +33 -8
  63. data/lib/axlsx/stylesheet/color.rb +15 -7
  64. data/lib/axlsx/stylesheet/dxf.rb +34 -9
  65. data/lib/axlsx/stylesheet/fill.rb +7 -2
  66. data/lib/axlsx/stylesheet/font.rb +65 -17
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +12 -4
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -5
  69. data/lib/axlsx/stylesheet/num_fmt.rb +14 -10
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +18 -5
  71. data/lib/axlsx/stylesheet/styles.rb +124 -82
  72. data/lib/axlsx/stylesheet/table_style.rb +19 -6
  73. data/lib/axlsx/stylesheet/table_style_element.rb +15 -4
  74. data/lib/axlsx/stylesheet/table_styles.rb +14 -5
  75. data/lib/axlsx/stylesheet/xf.rb +73 -18
  76. data/lib/axlsx/util/accessors.rb +10 -6
  77. data/lib/axlsx/util/buffered_zip_output_stream.rb +60 -0
  78. data/lib/axlsx/util/constants.rb +117 -104
  79. data/lib/axlsx/util/mime_type_utils.rb +3 -5
  80. data/lib/axlsx/util/options_parser.rb +3 -1
  81. data/lib/axlsx/util/serialized_attributes.rb +42 -17
  82. data/lib/axlsx/util/simple_typed_list.rb +47 -47
  83. data/lib/axlsx/util/storage.rb +11 -10
  84. data/lib/axlsx/util/validators.rb +101 -41
  85. data/lib/axlsx/util/zip_command.rb +10 -10
  86. data/lib/axlsx/version.rb +3 -1
  87. data/lib/axlsx/workbook/defined_name.rb +6 -4
  88. data/lib/axlsx/workbook/defined_names.rb +4 -2
  89. data/lib/axlsx/workbook/shared_strings_table.rb +8 -6
  90. data/lib/axlsx/workbook/workbook.rb +94 -79
  91. data/lib/axlsx/workbook/workbook_view.rb +3 -1
  92. data/lib/axlsx/workbook/workbook_views.rb +4 -2
  93. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +65 -8
  94. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +11 -7
  96. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  97. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +56 -0
  98. data/lib/axlsx/workbook/worksheet/border_creator.rb +5 -3
  99. data/lib/axlsx/workbook/worksheet/break.rb +3 -1
  100. data/lib/axlsx/workbook/worksheet/cell.rb +83 -64
  101. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +31 -27
  102. data/lib/axlsx/workbook/worksheet/cfvo.rb +11 -3
  103. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -1
  104. data/lib/axlsx/workbook/worksheet/col.rb +5 -3
  105. data/lib/axlsx/workbook/worksheet/col_breaks.rb +6 -4
  106. data/lib/axlsx/workbook/worksheet/color_scale.rb +12 -10
  107. data/lib/axlsx/workbook/worksheet/cols.rb +4 -2
  108. data/lib/axlsx/workbook/worksheet/comment.rb +8 -6
  109. data/lib/axlsx/workbook/worksheet/comments.rb +6 -4
  110. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +16 -5
  111. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +73 -16
  112. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +4 -2
  113. data/lib/axlsx/workbook/worksheet/data_bar.rb +14 -13
  114. data/lib/axlsx/workbook/worksheet/data_validation.rb +69 -28
  115. data/lib/axlsx/workbook/worksheet/data_validations.rb +4 -2
  116. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +7 -5
  117. data/lib/axlsx/workbook/worksheet/dimension.rb +4 -2
  118. data/lib/axlsx/workbook/worksheet/header_footer.rb +4 -2
  119. data/lib/axlsx/workbook/worksheet/icon_set.rb +38 -9
  120. data/lib/axlsx/workbook/worksheet/merged_cells.rb +6 -6
  121. data/lib/axlsx/workbook/worksheet/outline_pr.rb +6 -2
  122. data/lib/axlsx/workbook/worksheet/page_margins.rb +39 -11
  123. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_setup.rb +34 -9
  125. data/lib/axlsx/workbook/worksheet/pane.rb +17 -9
  126. data/lib/axlsx/workbook/worksheet/pivot_table.rb +20 -19
  127. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -6
  128. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -1
  129. data/lib/axlsx/workbook/worksheet/print_options.rb +3 -1
  130. data/lib/axlsx/workbook/worksheet/protected_range.rb +3 -1
  131. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +6 -4
  132. data/lib/axlsx/workbook/worksheet/rich_text.rb +3 -1
  133. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +46 -24
  134. data/lib/axlsx/workbook/worksheet/row.rb +11 -9
  135. data/lib/axlsx/workbook/worksheet/row_breaks.rb +7 -5
  136. data/lib/axlsx/workbook/worksheet/selection.rb +15 -7
  137. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -2
  138. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  139. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +6 -2
  140. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +8 -4
  141. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +11 -9
  142. data/lib/axlsx/workbook/worksheet/sheet_view.rb +38 -15
  143. data/lib/axlsx/workbook/worksheet/table.rb +9 -7
  144. data/lib/axlsx/workbook/worksheet/table_style_info.rb +4 -2
  145. data/lib/axlsx/workbook/worksheet/tables.rb +4 -2
  146. data/lib/axlsx/workbook/worksheet/worksheet.rb +56 -39
  147. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -2
  148. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +8 -2
  149. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +7 -5
  150. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +5 -3
  151. data/lib/axlsx.rb +56 -42
  152. data/lib/caxlsx.rb +3 -1
  153. metadata +39 -71
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The Cell Serializer class contains the logic for serializing cells based on their type.
3
5
  class CellSerializer
@@ -7,28 +9,30 @@ module Axlsx
7
9
  # @param [Integer] column_index The index of the cell's column
8
10
  # @param [String] str The string to apend serialization to.
9
11
  # @return [String]
10
- def to_xml_string(row_index, column_index, cell, str = '')
11
- str << ('<c r="' << Axlsx::cell_r(column_index, row_index) << '" s="' << cell.style.to_s << '" ')
12
+ def to_xml_string(row_index, column_index, cell, str = +'')
13
+ str << '<c r="'
14
+ str << Axlsx.col_ref(column_index) << Axlsx.row_ref(row_index)
15
+ str << '" s="' << cell.style_str << '" '
12
16
  return str << '/>' if cell.value.nil?
13
17
 
14
18
  method = cell.type
15
- self.send(method, cell, str)
19
+ send(method, cell, str)
16
20
  str << '</c>'
17
21
  end
18
22
 
19
23
  # builds an xml text run based on this cells attributes.
20
24
  # @param [String] str The string instance this run will be concated to.
21
25
  # @return [String]
22
- def run_xml_string(cell, str = '')
26
+ def run_xml_string(cell, str = +'')
23
27
  if cell.is_text_run?
24
28
  valid = RichTextRun::INLINE_STYLES - [:value, :type]
25
- data = Hash[Axlsx.instance_values_for(cell).map { |k, v| [k.to_sym, v] }]
26
- data = data.select { |key, value| valid.include?(key) && !value.nil? }
29
+ data = Axlsx.instance_values_for(cell).transform_keys(&:to_sym)
30
+ data = data.select { |key, value| !value.nil? && valid.include?(key) }
27
31
  RichText.new(cell.value.to_s, data).to_xml_string(str)
28
32
  elsif cell.contains_rich_text?
29
33
  cell.value.to_xml_string(str)
30
34
  else
31
- str << ('<t>' << cell.clean_value << '</t>')
35
+ str << '<t>' << cell.clean_value << '</t>'
32
36
  end
33
37
  str
34
38
  end
@@ -37,7 +41,7 @@ module Axlsx
37
41
  # @param [Cell] cell The cell that is being serialized
38
42
  # @param [String] str The string the serialized content will be appended to.
39
43
  # @return [String]
40
- def iso_8601(cell, str = '')
44
+ def iso_8601(cell, str = +'')
41
45
  value_serialization 'd', cell.value, str
42
46
  end
43
47
 
@@ -45,23 +49,23 @@ module Axlsx
45
49
  # @param [Cell] cell The cell that is being serialized
46
50
  # @param [String] str The string the serialized content will be appended to.
47
51
  # @return [String]
48
- def date(cell, str = '')
49
- value_serialization false, DateTimeConverter::date_to_serial(cell.value).to_s, str
52
+ def date(cell, str = +'')
53
+ value_serialization false, DateTimeConverter.date_to_serial(cell.value).to_s, str
50
54
  end
51
55
 
52
56
  # Serializes cells that are type time
53
57
  # @param [Cell] cell The cell that is being serialized
54
58
  # @param [String] str The string the serialized content will be appended to.
55
59
  # @return [String]
56
- def time(cell, str = '')
57
- value_serialization false, DateTimeConverter::time_to_serial(cell.value).to_s, str
60
+ def time(cell, str = +'')
61
+ value_serialization false, DateTimeConverter.time_to_serial(cell.value).to_s, str
58
62
  end
59
63
 
60
64
  # Serializes cells that are type boolean
61
65
  # @param [Cell] cell The cell that is being serialized
62
66
  # @param [String] str The string the serialized content will be appended to.
63
67
  # @return [String]
64
- def boolean(cell, str = '')
68
+ def boolean(cell, str = +'')
65
69
  value_serialization 'b', cell.value.to_s, str
66
70
  end
67
71
 
@@ -69,7 +73,7 @@ module Axlsx
69
73
  # @param [Cell] cell The cell that is being serialized
70
74
  # @param [String] str The string the serialized content will be appended to.
71
75
  # @return [String]
72
- def float(cell, str = '')
76
+ def float(cell, str = +'')
73
77
  numeric cell, str
74
78
  end
75
79
 
@@ -77,7 +81,7 @@ module Axlsx
77
81
  # @param [Cell] cell The cell that is being serialized
78
82
  # @param [String] str The string the serialized content will be appended to.
79
83
  # @return [String]
80
- def integer(cell, str = '')
84
+ def integer(cell, str = +'')
81
85
  numeric cell, str
82
86
  end
83
87
 
@@ -85,25 +89,25 @@ module Axlsx
85
89
  # @param [Cell] cell The cell that is being serialized
86
90
  # @param [String] str The string the serialized content will be appended to.
87
91
  # @return [String]
88
- def formula_serialization(cell, str = '')
89
- str << ('t="str"><f>' << cell.clean_value.to_s.sub('=', '') << '</f>')
90
- str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil?
92
+ def formula_serialization(cell, str = +'')
93
+ str << 't="str"><f>' << cell.clean_value.delete_prefix(FORMULA_PREFIX) << '</f>'
94
+ str << '<v>' << cell.formula_value.to_s << '</v>' unless cell.formula_value.nil?
91
95
  end
92
96
 
93
97
  # Serializes cells that are type array formula
94
98
  # @param [Cell] cell The cell that is being serialized
95
99
  # @param [String] str The string the serialized content will be appended to.
96
100
  # @return [String]
97
- def array_formula_serialization(cell, str = '')
98
- str << ('t="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.to_s.sub('{=', '').sub(/}$/, '') << '</f>')
99
- str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil?
101
+ def array_formula_serialization(cell, str = +'')
102
+ str << 't="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.delete_prefix(ARRAY_FORMULA_PREFIX).delete_suffix(ARRAY_FORMULA_SUFFIX) << '</f>'
103
+ str << '<v>' << cell.formula_value.to_s << '</v>' unless cell.formula_value.nil?
100
104
  end
101
105
 
102
106
  # Serializes cells that are type inline_string
103
107
  # @param [Cell] cell The cell that is being serialized
104
108
  # @param [String] str The string the serialized content will be appended to.
105
109
  # @return [String]
106
- def inline_string_serialization(cell, str = '')
110
+ def inline_string_serialization(cell, str = +'')
107
111
  str << 't="inlineStr"><is>'
108
112
  run_xml_string cell, str
109
113
  str << '</is>'
@@ -113,7 +117,7 @@ module Axlsx
113
117
  # @param [Cell] cell The cell that is being serialized
114
118
  # @param [String] str The string the serialized content will be appended to.
115
119
  # @return [String]
116
- def string(cell, str = '')
120
+ def string(cell, str = +'')
117
121
  if cell.is_array_formula?
118
122
  array_formula_serialization cell, str
119
123
  elsif cell.is_formula?
@@ -151,13 +155,13 @@ module Axlsx
151
155
 
152
156
  private
153
157
 
154
- def numeric(cell, str = '')
158
+ def numeric(cell, str = +'')
155
159
  value_serialization 'n', cell.value, str
156
160
  end
157
161
 
158
- def value_serialization(serialization_type, serialization_value, str = '')
159
- str << ('t="' << serialization_type.to_s << '"') if serialization_type
160
- str << ('><v>' << serialization_value.to_s << '</v>')
162
+ def value_serialization(serialization_type, serialization_value, str = +'')
163
+ str << 't="' << serialization_type.to_s << '"' if serialization_type
164
+ str << '><v>' << serialization_value.to_s << '</v>'
161
165
  end
162
166
  end
163
167
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Conditional Format Value Object
3
5
  # Describes the values of the interpolation points in a gradient scale. This object is used by ColorScale, DataBar and IconSet classes
@@ -38,10 +40,16 @@ module Axlsx
38
40
  attr_reader :val
39
41
 
40
42
  # @see type
41
- def type=(v); Axlsx::validate_conditional_formatting_value_object_type(v); @type = v end
43
+ def type=(v)
44
+ Axlsx.validate_conditional_formatting_value_object_type(v)
45
+ @type = v
46
+ end
42
47
 
43
48
  # @see gte
44
- def gte=(v); Axlsx::validate_boolean(v); @gte = v end
49
+ def gte=(v)
50
+ Axlsx.validate_boolean(v)
51
+ @gte = v
52
+ end
45
53
 
46
54
  # @see val
47
55
  def val=(v)
@@ -53,7 +61,7 @@ module Axlsx
53
61
  # serialize the Csvo object
54
62
  # @param [String] str
55
63
  # @return [String]
56
- def to_xml_string(str = '')
64
+ def to_xml_string(str = +'')
57
65
  serialized_tag('cfvo', str)
58
66
  end
59
67
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A collection of Cfvo objects that initializes with the required
3
5
  # first two items
@@ -9,7 +11,7 @@ module Axlsx
9
11
  # Serialize the Cfvo object
10
12
  # @param [String] str
11
13
  # @return [String]
12
- def to_xml_string(str = '')
14
+ def to_xml_string(str = +'')
13
15
  each { |cfvo| cfvo.to_xml_string(str) }
14
16
  end
15
17
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The Col class defines column attributes for columns in sheets.
3
5
  class Col
@@ -86,7 +88,7 @@ module Axlsx
86
88
  # @see Col#outline
87
89
  def outline_level=(v)
88
90
  Axlsx.validate_unsigned_numeric(v)
89
- raise ArgumentError, 'outlineLevel must be between 0 and 7' unless 0 <= v && v <= 7
91
+ raise ArgumentError, 'outlineLevel must be between 0 and 7' unless v >= 0 && v <= 7
90
92
 
91
93
  @outline_level = v
92
94
  end
@@ -112,7 +114,7 @@ module Axlsx
112
114
  # current @width value.
113
115
  # TODO!!!
114
116
  # Axlsx.validate_unsigned_numeric(v) unless v == nil
115
- @custom_width = @best_fit = v != nil
117
+ @custom_width = @best_fit = !v.nil?
116
118
  @width = v.nil? ? v : [v, MAX_WIDTH].min
117
119
  end
118
120
 
@@ -135,7 +137,7 @@ module Axlsx
135
137
  # Serialize this columns data to an xml string
136
138
  # @param [String] str
137
139
  # @return [String]
138
- def to_xml_string(str = '')
140
+ def to_xml_string(str = +'')
139
141
  serialized_tag('col', str)
140
142
  end
141
143
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A collection of Brake objects.
3
5
  # Please do not use this class directly. Instead use
@@ -5,7 +7,7 @@ module Axlsx
5
7
  class ColBreaks < SimpleTypedList
6
8
  # Instantiates a new list restricted to Break types
7
9
  def initialize
8
- super Break
10
+ super(Break)
9
11
  end
10
12
 
11
13
  # A column break specific helper for adding a break.
@@ -14,7 +16,7 @@ module Axlsx
14
16
  # Break will be passed to the created break object.
15
17
  # @see Break
16
18
  def add_break(options)
17
- self << Break.new(options.merge(:max => 1048575, :man => true))
19
+ self << Break.new(options.merge(max: 1048575, man: true))
18
20
  last
19
21
  end
20
22
 
@@ -23,10 +25,10 @@ module Axlsx
23
25
  # <colBreaks count="1" manualBreakCount="1">
24
26
  # <brk id="3" max="1048575" man="1"/>
25
27
  # </colBreaks>
26
- def to_xml_string(str = '')
28
+ def to_xml_string(str = +'')
27
29
  return if empty?
28
30
 
29
- str << ('<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">')
31
+ str << '<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">'
30
32
  each { |brk| brk.to_xml_string(str) }
31
33
  str << '</colBreaks>'
32
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Conditional Format Rule color scale object
3
5
  # Describes a gradated color scale in this conditional formatting rule.
@@ -10,8 +12,8 @@ module Axlsx
10
12
  # These are the default conditional formatting value objects
11
13
  # that define a two tone color gradient.
12
14
  def default_cfvos
13
- [{ :type => :min, :val => 0, :color => 'FFFF7128' },
14
- { :type => :max, :val => 0, :color => 'FFFFEF9C' }]
15
+ [{ type: :min, val: 0, color: 'FFFF7128' },
16
+ { type: :max, val: 0, color: 'FFFFEF9C' }]
15
17
  end
16
18
 
17
19
  # A builder for two tone color gradient
@@ -20,7 +22,7 @@ module Axlsx
20
22
  # color_scale = Axlsx::ColorScale.two_tone
21
23
  # @see examples/example.rb conditional formatting examples.
22
24
  def two_tone
23
- self.new
25
+ new
24
26
  end
25
27
 
26
28
  # A builder for three tone color gradient
@@ -29,9 +31,9 @@ module Axlsx
29
31
  # color_scale = Axlsx::ColorScale.three_tone
30
32
  # @see examples/example.rb conditional formatting examples.
31
33
  def three_tone
32
- self.new({ :type => :min, :val => 0, :color => 'FFF8696B' },
33
- { :type => :percent, :val => '50', :color => 'FFFFEB84' },
34
- { :type => :max, :val => 0, :color => 'FF63BE7B' })
34
+ new({ type: :min, val: 0, color: 'FFF8696B' },
35
+ { type: :percent, val: '50', color: 'FFFFEB84' },
36
+ { type: :max, val: 0, color: 'FF63BE7B' })
35
37
  end
36
38
  end
37
39
  # A simple typed list of cfvos
@@ -66,9 +68,9 @@ module Axlsx
66
68
  # @option [Any] val The value of the cfvo to add
67
69
  # @option [String] The rgb color for the cfvo
68
70
  def add(options = {})
69
- value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0)
70
- colors << Color.new(:rgb => options[:color] || "FF000000")
71
- { :cfvo => value_objects.last, :color => colors.last }
71
+ value_objects << Cfvo.new(type: options[:type] || :min, val: options[:val] || 0)
72
+ colors << Color.new(rgb: options[:color] || "FF000000")
73
+ { cfvo: value_objects.last, color: colors.last }
72
74
  end
73
75
 
74
76
  # removes the cfvo and color pair at the index specified.
@@ -82,7 +84,7 @@ module Axlsx
82
84
  # Serialize this color_scale object data to an xml string
83
85
  # @param [String] str
84
86
  # @return [String]
85
- def to_xml_string(str = '')
87
+ def to_xml_string(str = +'')
86
88
  str << '<colorScale>'
87
89
  value_objects.to_xml_string(str)
88
90
  colors.each { |color| color.to_xml_string(str) }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The cols class manages the col object used to manage column widths.
3
5
  # This is where the magic happens with autowidth
@@ -5,14 +7,14 @@ module Axlsx
5
7
  def initialize(worksheet)
6
8
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
7
9
 
8
- super Col
10
+ super(Col)
9
11
  @worksheet = worksheet
10
12
  end
11
13
 
12
14
  # Serialize the Cols object
13
15
  # @param [String] str
14
16
  # @return [String]
15
- def to_xml_string(str = '')
17
+ def to_xml_string(str = +'')
16
18
  return if empty?
17
19
 
18
20
  str << '<cols>'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A comment is the text data for a comment
3
5
  class Comment
@@ -59,17 +61,17 @@ module Axlsx
59
61
  # serialize the object
60
62
  # @param [String] str
61
63
  # @return [String]
62
- def to_xml_string(str = "")
64
+ def to_xml_string(str = +'')
63
65
  author = @comments.authors[author_index]
64
- str << ('<comment ref="' << ref << '" authorId="' << author_index.to_s << '">')
66
+ str << '<comment ref="' << ref << '" authorId="' << author_index.to_s << '">'
65
67
  str << '<text>'
66
68
  unless author.to_s == ""
67
69
  str << '<r><rPr><b/><color indexed="81"/></rPr>'
68
- str << ("<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>")
70
+ str << "<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>"
69
71
  end
70
72
  str << '<r>'
71
73
  str << '<rPr><color indexed="81"/></rPr>'
72
- str << ('<t>' << ::CGI.escapeHTML(text) << '</t></r></text>')
74
+ str << '<t>' << ::CGI.escapeHTML(text) << '</t></r></text>'
73
75
  str << '</comment>'
74
76
  end
75
77
 
@@ -78,8 +80,8 @@ module Axlsx
78
80
  # initialize the vml shape based on this comment's ref/position in the worksheet.
79
81
  # by default, all columns are 5 columns wide and 5 rows high
80
82
  def initialize_vml_shape
81
- pos = Axlsx::name_to_indices(ref)
82
- @vml_shape = VmlShape.new(:row => pos[1], :column => pos[0], :visible => @visible) do |vml|
83
+ pos = Axlsx.name_to_indices(ref)
84
+ @vml_shape = VmlShape.new(row: pos[1], column: pos[0], visible: @visible) do |vml|
83
85
  vml.left_column = vml.column
84
86
  vml.right_column = vml.column + 2
85
87
  vml.top_row = vml.row
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Comments is a collection of Comment objects for a worksheet
3
5
  class Comments < SimpleTypedList
@@ -18,7 +20,7 @@ module Axlsx
18
20
  # The part name for this object
19
21
  # @return [String]
20
22
  def pn
21
- "#{COMMENT_PN % (index + 1)}"
23
+ format(COMMENT_PN, index + 1)
22
24
  end
23
25
 
24
26
  # Creates a new Comments object
@@ -62,11 +64,11 @@ module Axlsx
62
64
  # serialize the object
63
65
  # @param [String] str
64
66
  # @return [String]
65
- def to_xml_string(str = "")
67
+ def to_xml_string(str = +'')
66
68
  str << '<?xml version="1.0" encoding="UTF-8"?>'
67
- str << ('<comments xmlns="' << XML_NS << '"><authors>')
69
+ str << '<comments xmlns="' << XML_NS << '"><authors>'
68
70
  authors.each do |author|
69
- str << ('<author>' << author.to_s << '</author>')
71
+ str << '<author>' << author.to_s << '</author>'
70
72
  end
71
73
  str << '</authors><commentList>'
72
74
  each do |comment|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Conditional formatting allows styling of ranges based on functions
3
5
  #
@@ -59,9 +61,15 @@ module Axlsx
59
61
  end
60
62
 
61
63
  # @see rules
62
- def rules=(v); @rules = v end
64
+ def rules=(v)
65
+ @rules = v
66
+ end
67
+
63
68
  # @see sqref
64
- def sqref=(v); Axlsx::validate_string(v); @sqref = v end
69
+ def sqref=(v)
70
+ Axlsx.validate_string(v)
71
+ @sqref = v
72
+ end
65
73
 
66
74
  # Serializes the conditional formatting element
67
75
  # @example Conditional Formatting XML looks like:
@@ -72,9 +80,12 @@ module Axlsx
72
80
  # </conditionalFormatting>
73
81
  # @param [String] str
74
82
  # @return [String]
75
- def to_xml_string(str = '')
76
- str << ('<conditionalFormatting sqref="' << sqref << '">')
77
- str << rules.collect { |rule| rule.to_xml_string }.join(' ')
83
+ def to_xml_string(str = +'')
84
+ str << '<conditionalFormatting sqref="' << sqref << '">'
85
+ rules.each_with_index do |rule, index|
86
+ str << ' ' unless index.zero?
87
+ rule.to_xml_string(str)
88
+ end
78
89
  str << '</conditionalFormatting>'
79
90
  end
80
91
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Conditional formatting rules specify formulas whose evaluations
3
5
  # format cells
@@ -153,33 +155,88 @@ module Axlsx
153
155
  end
154
156
 
155
157
  # @see type
156
- def type=(v); Axlsx::validate_conditional_formatting_type(v); @type = v end
158
+ def type=(v)
159
+ Axlsx.validate_conditional_formatting_type(v)
160
+ @type = v
161
+ end
162
+
157
163
  # @see aboveAverage
158
- def aboveAverage=(v); Axlsx::validate_boolean(v); @aboveAverage = v end
164
+ def aboveAverage=(v)
165
+ Axlsx.validate_boolean(v)
166
+ @aboveAverage = v
167
+ end
168
+
159
169
  # @see bottom
160
- def bottom=(v); Axlsx::validate_boolean(v); @bottom = v end
170
+ def bottom=(v)
171
+ Axlsx.validate_boolean(v)
172
+ @bottom = v
173
+ end
174
+
161
175
  # @see dxfId
162
- def dxfId=(v); Axlsx::validate_unsigned_numeric(v); @dxfId = v end
176
+ def dxfId=(v)
177
+ Axlsx.validate_unsigned_numeric(v)
178
+ @dxfId = v
179
+ end
180
+
163
181
  # @see equalAverage
164
- def equalAverage=(v); Axlsx::validate_boolean(v); @equalAverage = v end
182
+ def equalAverage=(v)
183
+ Axlsx.validate_boolean(v)
184
+ @equalAverage = v
185
+ end
186
+
165
187
  # @see priority
166
- def priority=(v); Axlsx::validate_unsigned_numeric(v); @priority = v end
188
+ def priority=(v)
189
+ Axlsx.validate_unsigned_numeric(v)
190
+ @priority = v
191
+ end
192
+
167
193
  # @see operator
168
- def operator=(v); Axlsx::validate_conditional_formatting_operator(v); @operator = v end
194
+ def operator=(v)
195
+ Axlsx.validate_conditional_formatting_operator(v)
196
+ @operator = v
197
+ end
198
+
169
199
  # @see text
170
- def text=(v); Axlsx::validate_string(v); @text = v end
200
+ def text=(v)
201
+ Axlsx.validate_string(v)
202
+ @text = v
203
+ end
204
+
171
205
  # @see percent
172
- def percent=(v); Axlsx::validate_boolean(v); @percent = v end
206
+ def percent=(v)
207
+ Axlsx.validate_boolean(v)
208
+ @percent = v
209
+ end
210
+
173
211
  # @see rank
174
- def rank=(v); Axlsx::validate_unsigned_numeric(v); @rank = v end
212
+ def rank=(v)
213
+ Axlsx.validate_unsigned_numeric(v)
214
+ @rank = v
215
+ end
216
+
175
217
  # @see stdDev
176
- def stdDev=(v); Axlsx::validate_unsigned_numeric(v); @stdDev = v end
218
+ def stdDev=(v)
219
+ Axlsx.validate_unsigned_numeric(v)
220
+ @stdDev = v
221
+ end
222
+
177
223
  # @see stopIfTrue
178
- def stopIfTrue=(v); Axlsx::validate_boolean(v); @stopIfTrue = v end
224
+ def stopIfTrue=(v)
225
+ Axlsx.validate_boolean(v)
226
+ @stopIfTrue = v
227
+ end
228
+
179
229
  # @see timePeriod
180
- def timePeriod=(v); Axlsx::validate_time_period_type(v); @timePeriod = v end
230
+ def timePeriod=(v)
231
+ Axlsx.validate_time_period_type(v)
232
+ @timePeriod = v
233
+ end
234
+
181
235
  # @see formula
182
- def formula=(v); [*v].each { |x| Axlsx::validate_string(x) }; @formula = [*v].map { |form| ::CGI.escapeHTML(form) } end
236
+ def formula=(v)
237
+ [*v].each { |x| Axlsx.validate_string(x) }
238
+ @formula = [*v].map { |form| ::CGI.escapeHTML(form) }
239
+ end
183
240
 
184
241
  # @see color_scale
185
242
  def color_scale=(v)
@@ -202,11 +259,11 @@ module Axlsx
202
259
  # Serializes the conditional formatting rule
203
260
  # @param [String] str
204
261
  # @return [String]
205
- def to_xml_string(str = '')
262
+ def to_xml_string(str = +'')
206
263
  str << '<cfRule '
207
264
  serialized_attributes str
208
265
  str << '>'
209
- str << ('<formula>' << [*self.formula].join('</formula><formula>') << '</formula>') if @formula
266
+ str << '<formula>' << [*formula].join('</formula><formula>') << '</formula>' if @formula
210
267
  @color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
211
268
  @data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
212
269
  @icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A simple, self serializing class for storing conditional formattings
3
5
  class ConditionalFormattings < SimpleTypedList
@@ -5,7 +7,7 @@ module Axlsx
5
7
  def initialize(worksheet)
6
8
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
7
9
 
8
- super ConditionalFormatting
10
+ super(ConditionalFormatting)
9
11
  @worksheet = worksheet
10
12
  end
11
13
 
@@ -14,7 +16,7 @@ module Axlsx
14
16
  attr_reader :worksheet
15
17
 
16
18
  # serialize the conditional formattings
17
- def to_xml_string(str = "")
19
+ def to_xml_string(str = +'')
18
20
  return if empty?
19
21
 
20
22
  each { |item| item.to_xml_string(str) }