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,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,10 +32,10 @@ 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
@@ -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,7 +11,7 @@ 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
16
  super(options)
17
17
  end
@@ -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
31
  super(str)
32
- str << ('<c:crossBetween val="' << @cross_between.to_s << '"/>')
32
+ str << '<c:crossBetween val="' << @cross_between.to_s << '"/>'
33
33
  str << '</c:valAx>'
34
34
  end
35
-
36
35
  end
37
36
  end
@@ -1,8 +1,8 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  module Axlsx
3
4
  # 3D attributes for a chart.
4
5
  class View3D
5
-
6
6
  include Axlsx::OptionsParser
7
7
 
8
8
  # Creates a new View3D for charts
@@ -12,16 +12,16 @@ module Axlsx
12
12
  # @option options [String] depth_percent
13
13
  # @option options [Boolean] r_ang_ax
14
14
  # @option options [Integer] perspective
15
- def initialize(options={})
16
- @rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
15
+ def initialize(options = {})
16
+ @rot_x, @h_percent, @rot_y, @depth_percent, @r_ang_ax, @perspective = nil, nil, nil, nil, nil, nil
17
17
  parse_options options
18
18
  end
19
19
 
20
20
  # Validation for hPercent
21
- H_PERCENT_REGEX = /0*(([5-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)/
21
+ H_PERCENT_REGEX = /0*(([5-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)/.freeze
22
22
 
23
23
  # validation for depthPercent
24
- DEPTH_PERCENT_REGEX = /0*(([2-9][0-9])|([1-9][0-9][0-9])|(1[0-9][0-9][0-9])|2000)/
24
+ DEPTH_PERCENT_REGEX = /0*(([2-9][0-9])|([1-9][0-9][0-9])|(1[0-9][0-9][0-9])|2000)/.freeze
25
25
 
26
26
  # x rotation for the chart
27
27
  # must be between -90 and 90
@@ -63,40 +63,40 @@ module Axlsx
63
63
  end
64
64
  alias :rotX= :rot_x=
65
65
 
66
- # @see h_percent
67
- def h_percent=(v)
68
- RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
69
- @h_percent = v
70
- end
66
+ # @see h_percent
67
+ def h_percent=(v)
68
+ RegexValidator.validate "#{self.class}.h_percent", H_PERCENT_REGEX, v
69
+ @h_percent = v
70
+ end
71
71
  alias :hPercent= :h_percent=
72
72
 
73
- # @see rot_y
74
- def rot_y=(v)
75
- RangeValidator.validate "View3D.rot_y", 0, 360, v
76
- @rot_y = v
77
- end
73
+ # @see rot_y
74
+ def rot_y=(v)
75
+ RangeValidator.validate "View3D.rot_y", 0, 360, v
76
+ @rot_y = v
77
+ end
78
78
  alias :rotY= :rot_y=
79
79
 
80
- # @see depth_percent
81
- def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
80
+ # @see depth_percent
81
+ def depth_percent=(v) RegexValidator.validate "#{self.class}.depth_percent", DEPTH_PERCENT_REGEX, v; @depth_percent = v; end
82
82
  alias :depthPercent= :depth_percent=
83
83
 
84
- # @see r_ang_ax
85
- def r_ang_ax=(v) Axlsx::validate_boolean(v); @r_ang_ax = v; end
84
+ # @see r_ang_ax
85
+ def r_ang_ax=(v) Axlsx.validate_boolean(v); @r_ang_ax = v; end
86
86
  alias :rAngAx= :r_ang_ax=
87
87
 
88
- # @see perspective
89
- def perspective=(v)
90
- RangeValidator.validate "View3D.perspective", 0, 240, v
91
- @perspective = v
92
- end
88
+ # @see perspective
89
+ def perspective=(v)
90
+ RangeValidator.validate "View3D.perspective", 0, 240, v
91
+ @perspective = v
92
+ end
93
93
 
94
94
  # DataTypeValidator.validate "#{self.class}.perspective", [Integer], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end
95
95
 
96
96
  # Serializes the object
97
97
  # @param [String] str
98
98
  # @return [String]
99
- def to_xml_string(str = '')
99
+ def to_xml_string(str = +'')
100
100
  str << '<c:view3D>'
101
101
  %w(rot_x h_percent rot_y depth_percent r_ang_ax perspective).each do |key|
102
102
  str << element_for_attribute(key, 'c')
@@ -105,11 +105,13 @@ module Axlsx
105
105
  end
106
106
 
107
107
  private
108
- # Note: move this to Axlsx module if we find the smae pattern elsewhere.
109
- def element_for_attribute(name, namespace='')
108
+
109
+ # NOTE: move this to Axlsx module if we find the same pattern elsewhere.
110
+ def element_for_attribute(name, namespace = '')
110
111
  val = Axlsx.instance_values_for(self)[name]
111
- return "" if val == nil
112
- "<%s:%s val='%s'/>" % [namespace, Axlsx::camel(name, false), val]
112
+ return "" if val.nil?
113
+
114
+ format("<%s:%s val='%s'/>", namespace, Axlsx.camel(name, false), val)
113
115
  end
114
116
  end
115
117
  end
@@ -1,42 +1,41 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
- # a vml drawing used for comments in excel.
3
+ module Axlsx
4
+ # a vml drawing used for comments in Excel.
4
5
  class VmlDrawing
5
-
6
6
  # creates a new Vml Drawing object.
7
7
  # @param [Comments] comments the comments object this drawing is associated with
8
8
  def initialize(comments)
9
9
  raise ArgumentError, "you must provide a comments object" unless comments.is_a?(Comments)
10
+
10
11
  @comments = comments
11
12
  end
12
13
 
13
14
  # The part name for this vml drawing
14
15
  # @return [String]
15
16
  def pn
16
- "#{VML_DRAWING_PN}" % (@comments.worksheet.index + 1)
17
+ format(VML_DRAWING_PN, @comments.worksheet.index + 1)
17
18
  end
18
19
 
19
20
  # serialize the vml_drawing to xml.
20
21
  # @param [String] str
21
22
  # @return [String]
22
- def to_xml_string(str = '')
23
- str << <<BAD_PROGRAMMER
24
- <xml xmlns:v="urn:schemas-microsoft-com:vml"
25
- xmlns:o="urn:schemas-microsoft-com:office:office"
26
- xmlns:x="urn:schemas-microsoft-com:office:excel">
27
- <o:shapelayout v:ext="edit">
28
- <o:idmap v:ext="edit" data="#{@comments.worksheet.index+1}"/>
29
- </o:shapelayout>
30
- <v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202"
31
- path="m0,0l0,21600,21600,21600,21600,0xe">
32
- <v:stroke joinstyle="miter"/>
33
- <v:path gradientshapeok="t" o:connecttype="rect"/>
34
- </v:shapetype>
35
- BAD_PROGRAMMER
23
+ def to_xml_string(str = +'')
24
+ str << <<~XML
25
+ <xml xmlns:v="urn:schemas-microsoft-com:vml"
26
+ xmlns:o="urn:schemas-microsoft-com:office:office"
27
+ xmlns:x="urn:schemas-microsoft-com:office:excel">
28
+ <o:shapelayout v:ext="edit">
29
+ <o:idmap v:ext="edit" data="#{@comments.worksheet.index + 1}"/>
30
+ </o:shapelayout>
31
+ <v:shapetype id="_x0000_t202" coordsize="21600,21600" o:spt="202"
32
+ path="m0,0l0,21600,21600,21600,21600,0xe">
33
+ <v:stroke joinstyle="miter"/>
34
+ <v:path gradientshapeok="t" o:connecttype="rect"/>
35
+ </v:shapetype>
36
+ XML
36
37
  @comments.each { |comment| comment.vml_shape.to_xml_string str }
37
38
  str << "</xml>"
38
-
39
39
  end
40
-
41
40
  end
42
41
  end
@@ -1,8 +1,8 @@
1
- module Axlsx
1
+ # frozen_string_literal: true
2
2
 
3
+ module Axlsx
3
4
  # A VmlShape is used to position and render a comment.
4
5
  class VmlShape
5
-
6
6
  include Axlsx::OptionsParser
7
7
  include Axlsx::Accessors
8
8
 
@@ -17,14 +17,14 @@ module Axlsx
17
17
  # @option options [Integer] right_offset
18
18
  # @option options [Integer] bottom_row
19
19
  # @option options [Integer] bottom_offset
20
- def initialize(options={})
20
+ def initialize(options = {})
21
21
  @row = @column = @left_column = @top_row = @right_column = @bottom_row = 0
22
22
  @left_offset = 15
23
23
  @top_offset = 2
24
24
  @right_offset = 50
25
25
  @bottom_offset = 5
26
26
  @visible = true
27
- @id = (0...8).map{65.+(rand(25)).chr}.join
27
+ @id = Array.new(8) { rand(65..89).chr }.join
28
28
  parse_options options
29
29
  yield self if block_given?
30
30
  end
@@ -37,30 +37,29 @@ module Axlsx
37
37
  # serialize the shape to a string
38
38
  # @param [String] str
39
39
  # @return [String]
40
- def to_xml_string(str ='')
41
- str << <<SHAME_ON_YOU
42
-
43
- <v:shape id="#{@id}" type="#_x0000_t202" fillcolor="#ffffa1 [80]" o:insetmode="auto"
44
- style="visibility:#{@visible ? 'visible' : 'hidden'}">
45
- <v:fill color2="#ffffa1 [80]"/>
46
- <v:shadow on="t" obscured="t"/>
47
- <v:path o:connecttype="none"/>
48
- <v:textbox style='mso-fit-text-with-word-wrap:t'>
49
- <div style='text-align:left'></div>
50
- </v:textbox>
40
+ def to_xml_string(str = +'')
41
+ str << <<~XML
51
42
 
52
- <x:ClientData ObjectType="Note">
53
- <x:MoveWithCells/>
54
- <x:SizeWithCells/>
55
- <x:Anchor>#{left_column}, #{left_offset}, #{top_row}, #{top_offset}, #{right_column}, #{right_offset}, #{bottom_row}, #{bottom_offset}</x:Anchor>
56
- <x:AutoFill>False</x:AutoFill>
57
- <x:Row>#{row}</x:Row>
58
- <x:Column>#{column}</x:Column>
59
- #{@visible ? '<x:Visible/>' : ''}
60
- </x:ClientData>
61
- </v:shape>
62
- SHAME_ON_YOU
43
+ <v:shape id="#{@id}" type="#_x0000_t202" fillcolor="#ffffa1 [80]" o:insetmode="auto"
44
+ style="visibility:#{@visible ? 'visible' : 'hidden'}">
45
+ <v:fill color2="#ffffa1 [80]"/>
46
+ <v:shadow on="t" obscured="t"/>
47
+ <v:path o:connecttype="none"/>
48
+ <v:textbox style='mso-fit-text-with-word-wrap:t'>
49
+ <div style='text-align:left'></div>
50
+ </v:textbox>
63
51
 
52
+ <x:ClientData ObjectType="Note">
53
+ <x:MoveWithCells/>
54
+ <x:SizeWithCells/>
55
+ <x:Anchor>#{left_column}, #{left_offset}, #{top_row}, #{top_offset}, #{right_column}, #{right_offset}, #{bottom_row}, #{bottom_offset}</x:Anchor>
56
+ <x:AutoFill>False</x:AutoFill>
57
+ <x:Row>#{row}</x:Row>
58
+ <x:Column>#{column}</x:Column>
59
+ #{@visible ? '<x:Visible/>' : ''}
60
+ </x:ClientData>
61
+ </v:shape>
62
+ XML
64
63
  end
65
64
  end
66
65
  end