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,12 +1,33 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # A SimpleTypedList is a type restrictive collection that allows some of the methods from Array and supports basic xml serialization.
3
5
  # @private
4
- class SimpleTypedList
6
+ class SimpleTypedList < Array
7
+ DESTRUCTIVE = [
8
+ 'replace', 'insert', 'collect!', 'map!', 'pop', 'delete_if',
9
+ 'reverse!', 'shift', 'shuffle!', 'slice!', 'sort!', 'uniq!',
10
+ 'unshift', 'zip', 'flatten!', 'fill', 'drop', 'drop_while',
11
+ 'clear'
12
+ ].freeze
13
+
14
+ DESTRUCTIVE.each do |name|
15
+ undef_method name
16
+ end
17
+
18
+ # We often call index(element) on instances of SimpleTypedList. Thus, we do not want to inherit Array
19
+ # implementation of == / eql? which walks the elements calling == / eql?. Instead we want the fast
20
+ # and original versions from BasicObject.
21
+ alias :== :equal?
22
+ alias :eql? :equal?
23
+
5
24
  # Creats a new typed list
6
25
  # @param [Array, Class] type An array of Class objects or a single Class object
7
26
  # @param [String] serialize_as The tag name to use in serialization
8
27
  # @raise [ArgumentError] if all members of type are not Class objects
9
- def initialize type, serialize_as = nil, start_size = 0
28
+ def initialize(type, serialize_as = nil, start_size = 0)
29
+ super(start_size)
30
+
10
31
  if type.is_a? Array
11
32
  type.each { |item| raise ArgumentError, "All members of type must be Class objects" unless item.is_a? Class }
12
33
  @allowed_types = type
@@ -16,7 +37,6 @@ module Axlsx
16
37
  @allowed_types = [type]
17
38
  end
18
39
  @serialize_as = serialize_as unless serialize_as.nil?
19
- @list = Array.new(start_size)
20
40
  end
21
41
 
22
42
  # The class constants of allowed types
@@ -37,16 +57,16 @@ module Axlsx
37
57
  # Transposes the list (without blowing up like ruby does)
38
58
  # any non populated cell in the matrix will be a nil value
39
59
  def transpose
40
- return @list.clone if @list.size == 0
60
+ return clone if size.zero?
41
61
 
42
- row_count = @list.size
43
- max_column_count = @list.map { |row| row.cells.size }.max
62
+ row_count = size
63
+ max_column_count = map { |row| row.cells.size }.max
44
64
  result = Array.new(max_column_count) { Array.new(row_count) }
45
65
  # yes, I know it is silly, but that warning is really annoying
46
66
  row_count.times do |row_index|
47
67
  max_column_count.times do |column_index|
48
- datum = if @list[row_index].cells.size >= max_column_count
49
- @list[row_index].cells[column_index]
68
+ datum = if self[row_index].cells.size >= max_column_count
69
+ self[row_index].cells[column_index]
50
70
  elsif block_given?
51
71
  yield(column_index, row_index)
52
72
  end
@@ -59,7 +79,7 @@ module Axlsx
59
79
  # Lock this list at the current size
60
80
  # @return [self]
61
81
  def lock
62
- @locked_at = @list.size
82
+ @locked_at = size
63
83
  self
64
84
  end
65
85
 
@@ -70,22 +90,16 @@ module Axlsx
70
90
  self
71
91
  end
72
92
 
73
- def to_ary
74
- @list
75
- end
76
-
77
- alias :to_a :to_ary
78
-
79
93
  # join operator
80
- # @param [Array] v the array to join
94
+ # @param [Array] other the array to join
81
95
  # @raise [ArgumentError] if any of the values being joined are not
82
96
  # one of the allowed types
83
97
  # @return [SimpleTypedList]
84
- def +(v)
85
- v.each do |item|
86
- DataTypeValidator.validate :SimpleTypedList_plus, @allowed_types, item
87
- @list << item
98
+ def +(other)
99
+ other.each do |item|
100
+ self << item
88
101
  end
102
+ super
89
103
  end
90
104
 
91
105
  # Concat operator
@@ -94,8 +108,8 @@ module Axlsx
94
108
  # @return [Integer] returns the index of the item added.
95
109
  def <<(v)
96
110
  DataTypeValidator.validate :SimpleTypedList_push, @allowed_types, v
97
- @list << v
98
- @list.size - 1
111
+ super
112
+ size - 1
99
113
  end
100
114
 
101
115
  alias :push :<<
@@ -108,17 +122,16 @@ module Axlsx
108
122
  return unless include? v
109
123
  raise ArgumentError, "Item is protected and cannot be deleted" if protected? index(v)
110
124
 
111
- @list.delete v
125
+ super
112
126
  end
113
127
 
114
128
  # delete the item from the list at the index position provided
115
129
  # @raise [ArgumentError] if the index is protected by locking
116
130
  # @return [Any] The item deleted
117
131
  def delete_at(index)
118
- @list[index]
119
132
  raise ArgumentError, "Item is protected and cannot be deleted" if protected? index
120
133
 
121
- @list.delete_at index
134
+ super
122
135
  end
123
136
 
124
137
  # positional assignment. Adds the item at the index specified
@@ -126,12 +139,12 @@ module Axlsx
126
139
  # @param [Any] v
127
140
  # @raise [ArgumentError] if the index is protected by locking
128
141
  # @raise [ArgumentError] if the item is not one of the allowed types
142
+ # @return [Any] The item added
129
143
  def []=(index, v)
130
144
  DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v
131
145
  raise ArgumentError, "Item is protected and cannot be changed" if protected? index
132
146
 
133
- @list[index] = v
134
- v
147
+ super
135
148
  end
136
149
 
137
150
  # inserts an item at the index specfied
@@ -139,42 +152,29 @@ module Axlsx
139
152
  # @param [Any] v
140
153
  # @raise [ArgumentError] if the index is protected by locking
141
154
  # @raise [ArgumentError] if the index is not one of the allowed types
155
+ # @return [Any] The item inserted
142
156
  def insert(index, v)
143
157
  DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v
144
158
  raise ArgumentError, "Item is protected and cannot be changed" if protected? index
145
159
 
146
- @list.insert(index, v)
160
+ super
147
161
  v
148
162
  end
149
163
 
150
164
  # determines if the index is protected
151
165
  # @param [Integer] index
152
- def protected? index
166
+ def protected?(index)
153
167
  return false unless locked_at.is_a? Integer
154
168
 
155
169
  index < locked_at
156
170
  end
157
171
 
158
- DESTRUCTIVE = ['replace', 'insert', 'collect!', 'map!', 'pop', 'delete_if',
159
- 'reverse!', 'shift', 'shuffle!', 'slice!', 'sort!', 'uniq!',
160
- 'unshift', 'zip', 'flatten!', 'fill', 'drop', 'drop_while',
161
- 'delete_if', 'clear']
162
- DELEGATES = Array.instance_methods - self.instance_methods - DESTRUCTIVE
163
-
164
- DELEGATES.each do |method|
165
- class_eval %{
166
- def #{method}(*args, &block)
167
- @list.send(:#{method}, *args, &block)
168
- end
169
- }
170
- end
171
-
172
- def to_xml_string(str = '')
172
+ def to_xml_string(str = +'')
173
173
  classname = @allowed_types[0].name.split('::').last
174
- el_name = serialize_as.to_s || (classname[0, 1].downcase + classname[1..-1])
175
- str << ('<' << el_name << ' count="' << size.to_s << '">')
174
+ el_name = serialize_as.to_s || (classname[0, 1].downcase + classname[1..])
175
+ str << '<' << el_name << ' count="' << size.to_s << '">'
176
176
  each { |item| item.to_xml_string(str) }
177
- str << ('</' << el_name << '>')
177
+ str << '</' << el_name << '>'
178
178
  end
179
179
  end
180
180
  end
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # The Storage class represents a storage object or stream in a compound file.
3
5
  class Storage
4
6
  # Packing for the Storage when pushing an array of items into a byte stream
5
7
  # Name, name length, type, color, left sibling, right sibling, child, classid, state, created, modified, sector, size
6
- PACKING = "s32 s1 c2 l3 x16 x4 q2 l q".freeze
8
+ PACKING = "s32 s1 c2 l3 x16 x4 q2 l q"
7
9
 
8
10
  # storage types
9
11
  TYPES = {
10
- :root => 5,
11
- :stream => 2,
12
- :storage => 1
12
+ root: 5,
13
+ stream: 2,
14
+ storage: 1
13
15
  }.freeze
14
16
 
15
17
  # Creates a byte string for this storage
@@ -31,9 +33,9 @@ module Axlsx
31
33
 
32
34
  # storage colors
33
35
  COLORS = {
34
- :red => 0,
35
- :black => 1
36
- }
36
+ red: 0,
37
+ black: 1
38
+ }.freeze
37
39
 
38
40
  # The color of this node in the directory tree. Defaults to black if not specified
39
41
  # @return [Integer] color
@@ -61,7 +63,6 @@ module Axlsx
61
63
  def name=(v)
62
64
  @name = v.bytes.to_a << 0
63
65
  @name_size = @name.size * 2
64
- @name
65
66
  end
66
67
 
67
68
  # The size of the stream
@@ -74,7 +75,7 @@ module Axlsx
74
75
  # @param [String] v The data for this storages stream
75
76
  # @return [Array]
76
77
  def data=(v)
77
- Axlsx::validate_string(v)
78
+ Axlsx.validate_string(v)
78
79
  self.type = TYPES[:stream] unless @type
79
80
  @size = v.size
80
81
  @data = v.bytes.to_a
@@ -132,7 +133,7 @@ module Axlsx
132
133
  @left = @right = @child = -1
133
134
  @sector = @size = @created = @modified = 0
134
135
  options.each do |o|
135
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
136
+ send(:"#{o[0]}=", o[1]) if respond_to? :"#{o[0]}="
136
137
  end
137
138
  @color ||= COLORS[:black]
138
139
  @type ||= (data.nil? ? TYPES[:storage] : TYPES[:stream])
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # Validate a value against a specific list of allowed values.
3
5
  class RestrictionValidator
@@ -8,7 +10,7 @@ module Axlsx
8
10
  # @raise [ArgumentError] Raised if the value provided is not in the list of choices.
9
11
  # @return [Boolean] true if validation succeeds.
10
12
  def self.validate(name, choices, v)
11
- raise ArgumentError, (ERR_RESTRICTION % [v.to_s, name, choices.inspect]) unless choices.include?(v)
13
+ raise ArgumentError, format(ERR_RESTRICTION, v.to_s, name, choices.inspect) unless choices.include?(v)
12
14
 
13
15
  true
14
16
  end
@@ -29,7 +31,7 @@ module Axlsx
29
31
  else
30
32
  min < value && value < max
31
33
  end
32
- raise ArgumentError, (ERR_RANGE % [value.inspect, min.to_s, max.to_s, inclusive]) unless passes
34
+ raise ArgumentError, format(ERR_RANGE, value.inspect, min.to_s, max.to_s, inclusive) unless passes
33
35
  end
34
36
  end
35
37
 
@@ -39,7 +41,7 @@ module Axlsx
39
41
  # @param [Regexp] regex The regular expression to evaluate
40
42
  # @param [Any] v The value to validate.
41
43
  def self.validate(name, regex, v)
42
- raise ArgumentError, (ERR_REGEX % [v.inspect, regex.to_s]) unless (v.respond_to?(:to_s) && v.to_s.match(regex))
44
+ raise ArgumentError, format(ERR_REGEX, v.inspect, regex.to_s) unless v.respond_to?(:to_s) && regex.match?(v.to_s)
43
45
  end
44
46
  end
45
47
 
@@ -53,14 +55,14 @@ module Axlsx
53
55
  # @return [Boolean] true if validation succeeds.
54
56
  # @see validate_boolean
55
57
  def self.validate(name, types, v, other = false)
56
- if other.is_a?(Proc)
57
- raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v)
58
+ if other.is_a?(Proc) && !other.call(v)
59
+ raise ArgumentError, format(ERR_TYPE, v.inspect, name, types.inspect)
58
60
  end
61
+
59
62
  v_class = v.is_a?(Class) ? v : v.class
60
- Array(types).each do |t|
61
- return if v_class <= t
62
- end
63
- raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
63
+ return if Array(types).any? { |t| v_class <= t }
64
+
65
+ raise ArgumentError, format(ERR_TYPE, v.inspect, name, types.inspect)
64
66
  end
65
67
  end
66
68
 
@@ -68,7 +70,7 @@ module Axlsx
68
70
  # @para, [Any] v the value to validate
69
71
  # @raise [ArgumentError] raised if the value cannot be converted to an integer
70
72
  def self.validate_integerish(v)
71
- raise ArgumentError, (ERR_INTEGERISH % v.inspect) unless (v.respond_to?(:to_i) && v.to_i.is_a?(Integer))
73
+ raise ArgumentError, format(ERR_INTEGERISH, v.inspect) unless v.respond_to?(:to_i) && v.to_i.is_a?(Integer)
72
74
  end
73
75
 
74
76
  # Requires that the value is between -54000000 and 54000000
@@ -76,11 +78,11 @@ module Axlsx
76
78
  # @raise [ArgumentError] raised if the value cannot be converted to an integer between the allowed angle values for chart label rotation.
77
79
  # @return [Boolean] true if the data is valid
78
80
  def self.validate_angle(v)
79
- raise ArgumentError, (ERR_ANGLE % v.inspect) unless (v.to_i >= -5400000 && v.to_i <= 5400000)
81
+ raise ArgumentError, format(ERR_ANGLE, v.inspect) unless v.to_i >= -5400000 && v.to_i <= 5400000
80
82
  end
81
83
 
82
84
  # Validates an unsigned intger
83
- UINT_VALIDATOR = lambda { |arg| arg.respond_to?(:>=) && arg >= 0 }
85
+ UINT_VALIDATOR = ->(arg) { arg.respond_to?(:>=) && arg >= 0 }
84
86
 
85
87
  # Requires that the value is a Integer and is greater or equal to 0
86
88
  # @param [Any] v The value validated
@@ -104,12 +106,16 @@ module Axlsx
104
106
  DataTypeValidator.validate :signed_int, Integer, v
105
107
  end
106
108
 
109
+ VALID_BOOLEAN_CLASSES = [TrueClass, FalseClass, Integer, String, Symbol].freeze
110
+ VALID_BOOLEAN_VALUES = [true, false, 1, 0, '1', '0', 'true', 'false', :true, :false].freeze
111
+ BOOLEAN_VALIDATOR = ->(arg) { VALID_BOOLEAN_VALUES.include?(arg) }
112
+
107
113
  # Requires that the value is a form that can be evaluated as a boolean in an xml document.
108
114
  # The value must be an instance of String, Integer, Symbol, TrueClass or FalseClass and
109
115
  # it must be one of 0, 1, "true", "false", :true, :false, true, false, "0", or "1"
110
116
  # @param [Any] v The value validated
111
117
  def self.validate_boolean(v)
112
- DataTypeValidator.validate(:boolean, [String, Integer, Symbol, TrueClass, FalseClass], v, lambda { |arg| [0, 1, "true", "false", :true, :false, true, false, "0", "1"].include?(arg) })
118
+ DataTypeValidator.validate(:boolean, VALID_BOOLEAN_CLASSES, v, BOOLEAN_VALIDATOR)
113
119
  end
114
120
 
115
121
  # Requires that the value is a String
@@ -130,53 +136,71 @@ module Axlsx
130
136
  RegexValidator.validate "number_with_unit", /\A[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)\Z/, v
131
137
  end
132
138
 
139
+ SCALE_10_400_VALIDATOR = ->(arg) { arg >= 10 && arg <= 400 }
140
+
133
141
  # Requires that the value is an integer ranging from 10 to 400.
134
142
  def self.validate_scale_10_400(v)
135
- DataTypeValidator.validate "page_scale", Integer, v, lambda { |arg| arg >= 10 && arg <= 400 }
143
+ DataTypeValidator.validate "page_scale", Integer, v, SCALE_10_400_VALIDATOR
136
144
  end
137
145
 
146
+ SCALE_0_10_400_VALIDATOR = ->(arg) { arg == 0 || (arg >= 10 && arg <= 400) }
147
+
138
148
  # Requires that the value is an integer ranging from 10 to 400 or 0.
139
149
  def self.validate_scale_0_10_400(v)
140
- DataTypeValidator.validate "page_scale", Integer, v, lambda { |arg| arg == 0 || (arg >= 10 && arg <= 400) }
150
+ DataTypeValidator.validate "page_scale", Integer, v, SCALE_0_10_400_VALIDATOR
141
151
  end
142
152
 
153
+ VALID_PAGE_ORIENTATION_VALUES = [:default, :landscape, :portrait].freeze
154
+
143
155
  # Requires that the value is one of :default, :landscape, or :portrait.
144
156
  def self.validate_page_orientation(v)
145
- RestrictionValidator.validate "page_orientation", [:default, :landscape, :portrait], v
157
+ RestrictionValidator.validate "page_orientation", VALID_PAGE_ORIENTATION_VALUES, v
146
158
  end
147
159
 
160
+ VALID_CELL_U_VALUES = [:none, :single, :double, :singleAccounting, :doubleAccounting].freeze
161
+
148
162
  # Requires that the value is one of :none, :single, :double, :singleAccounting, :doubleAccounting
149
163
  def self.validate_cell_u(v)
150
- RestrictionValidator.validate "cell run style u", [:none, :single, :double, :singleAccounting, :doubleAccounting], v
164
+ RestrictionValidator.validate "cell run style u", VALID_CELL_U_VALUES, v
151
165
  end
152
166
 
167
+ VALID_FAMILY_VALUES = (1..5).freeze
168
+
153
169
  # validates cell style family which must be between 1 and 5
154
170
  def self.validate_family(v)
155
- RestrictionValidator.validate "cell run style family", 1..5, v
171
+ RestrictionValidator.validate "cell run style family", VALID_FAMILY_VALUES, v
156
172
  end
157
173
 
174
+ VALID_PATTERN_TYPE_VALUES = [:none, :solid, :mediumGray, :darkGray, :lightGray, :darkHorizontal, :darkVertical, :darkDown, :darkUp, :darkGrid,
175
+ :darkTrellis, :lightHorizontal, :lightVertical, :lightDown, :lightUp, :lightGrid, :lightTrellis, :gray125, :gray0625].freeze
176
+
158
177
  # Requires that the value is valid pattern type.
159
178
  # valid pattern types must be one of :none, :solid, :mediumGray, :darkGray, :lightGray, :darkHorizontal, :darkVertical, :darkDown,
160
179
  # :darkUp, :darkGrid, :darkTrellis, :lightHorizontal, :lightVertical, :lightDown, :lightUp, :lightGrid, :lightTrellis, :gray125, or :gray0625.
161
180
  # @param [Any] v The value validated
162
181
  def self.validate_pattern_type(v)
163
- RestrictionValidator.validate :pattern_type, [:none, :solid, :mediumGray, :darkGray, :lightGray, :darkHorizontal, :darkVertical, :darkDown, :darkUp, :darkGrid,
164
- :darkTrellis, :lightHorizontal, :lightVertical, :lightDown, :lightUp, :lightGrid, :lightTrellis, :gray125, :gray0625], v
182
+ RestrictionValidator.validate :pattern_type, VALID_PATTERN_TYPE_VALUES, v
165
183
  end
166
184
 
185
+ VALID_TIME_PERIOD_TYPE_VALUES = [:today, :yesterday, :tomorrow, :last7Days, :thisMonth, :lastMonth, :nextMonth, :thisWeek, :lastWeek, :nextWeek].freeze
186
+
167
187
  # Requires that the value is one of the ST_TimePeriod types
168
188
  # valid time period types are today, yesterday, tomorrow, last7Days,
169
189
  # thisMonth, lastMonth, nextMonth, thisWeek, lastWeek, nextWeek
170
190
  def self.validate_time_period_type(v)
171
- RestrictionValidator.validate :time_period_type, [:today, :yesterday, :tomorrow, :last7Days, :thisMonth, :lastMonth, :nextMonth, :thisWeek, :lastWeek, :nextWeek], v
191
+ RestrictionValidator.validate :time_period_type, VALID_TIME_PERIOD_TYPE_VALUES, v
172
192
  end
173
193
 
194
+ VALID_ICON_SET_VALUES = ["3Arrows", "3ArrowsGray", "3Flags", "3TrafficLights1", "3TrafficLights2", "3Signs", "3Symbols", "3Symbols2", "4Arrows", "4ArrowsGray", "4RedToBlack", "4Rating", "4TrafficLights", "5Arrows", "5ArrowsGray", "5Rating", "5Quarters"].freeze
195
+
174
196
  # Requires that the value is one of the valid ST_IconSet types
175
197
  # Allowed values are: 3Arrows, 3ArrowsGray, 3Flags, 3TrafficLights1, 3TrafficLights2, 3Signs, 3Symbols, 3Symbols2, 4Arrows, 4ArrowsGray, 4RedToBlack, 4Rating, 4TrafficLights, 5Arrows, 5ArrowsGray, 5Rating, 5Quarters
176
198
  def self.validate_icon_set(v)
177
- RestrictionValidator.validate :iconSet, ["3Arrows", "3ArrowsGray", "3Flags", "3TrafficLights1", "3TrafficLights2", "3Signs", "3Symbols", "3Symbols2", "4Arrows", "4ArrowsGray", "4RedToBlack", "4Rating", "4TrafficLights", "5Arrows", "5ArrowsGray", "5Rating", "5Quarters"], v
199
+ RestrictionValidator.validate :iconSet, VALID_ICON_SET_VALUES, v
178
200
  end
179
201
 
202
+ VALID_CONDITIONAL_FORMATTING_TYPE_VALUES = [:expression, :cellIs, :colorScale, :dataBar, :iconSet, :top10, :uniqueValues, :duplicateValues, :containsText, :notContainsText, :beginsWith, :endsWith, :containsBlanks, :notContainsBlanks, :containsErrors, :notContainsErrors, :timePeriod, :aboveAverage].freeze
203
+
180
204
  # Requires that the value is valid conditional formatting type.
181
205
  # valid types must be one of expression, cellIs, colorScale,
182
206
  # dataBar, iconSet, top10, uniqueValues, duplicateValues,
@@ -185,131 +209,167 @@ module Axlsx
185
209
  # notContainsErrors, timePeriod, aboveAverage
186
210
  # @param [Any] v The value validated
187
211
  def self.validate_conditional_formatting_type(v)
188
- RestrictionValidator.validate :conditional_formatting_type, [:expression, :cellIs, :colorScale, :dataBar, :iconSet, :top10, :uniqueValues, :duplicateValues, :containsText, :notContainsText, :beginsWith, :endsWith, :containsBlanks, :notContainsBlanks, :containsErrors, :notContainsErrors, :timePeriod, :aboveAverage], v
212
+ RestrictionValidator.validate :conditional_formatting_type, VALID_CONDITIONAL_FORMATTING_TYPE_VALUES, v
189
213
  end
190
214
 
215
+ VALID_CONDITION_FORMATTING_VALUE_OBJECT_TYPE_VALUES = [:num, :percent, :max, :min, :formula, :percentile].freeze
216
+
191
217
  # Requires thatt he value is a valid conditional formatting value object type.
192
218
  # valid types must be one of num, percent, max, min, formula and percentile
193
219
  def self.validate_conditional_formatting_value_object_type(v)
194
- RestrictionValidator.validate :conditional_formatting_value_object_type, [:num, :percent, :max, :min, :formula, :percentile], v
220
+ RestrictionValidator.validate :conditional_formatting_value_object_type, VALID_CONDITION_FORMATTING_VALUE_OBJECT_TYPE_VALUES, v
195
221
  end
196
222
 
223
+ VALID_CONDITIONAL_FORMATTING_OPERATOR_VALUES = [:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween, :containsText, :notContains, :beginsWith, :endsWith].freeze
224
+
197
225
  # Requires that the value is valid conditional formatting operator.
198
226
  # valid operators must be one of lessThan, lessThanOrEqual, equal,
199
227
  # notEqual, greaterThanOrEqual, greaterThan, between, notBetween,
200
228
  # containsText, notContains, beginsWith, endsWith
201
229
  # @param [Any] v The value validated
202
230
  def self.validate_conditional_formatting_operator(v)
203
- RestrictionValidator.validate :conditional_formatting_type, [:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween, :containsText, :notContains, :beginsWith, :endsWith], v
231
+ RestrictionValidator.validate :conditional_formatting_type, VALID_CONDITIONAL_FORMATTING_OPERATOR_VALUES, v
204
232
  end
205
233
 
234
+ VALID_GRADIENT_TYPE_VALUES = [:linear, :path].freeze
235
+
206
236
  # Requires that the value is a gradient_type.
207
237
  # valid types are :linear and :path
208
238
  # @param [Any] v The value validated
209
239
  def self.validate_gradient_type(v)
210
- RestrictionValidator.validate :gradient_type, [:linear, :path], v
240
+ RestrictionValidator.validate :gradient_type, VALID_GRADIENT_TYPE_VALUES, v
211
241
  end
212
242
 
243
+ VALID_SCATTER_STYLE_VALUES = [:none, :line, :lineMarker, :marker, :smooth, :smoothMarker].freeze
244
+
213
245
  # Requires that the value is a valid scatterStyle
214
246
  # must be one of :none | :line | :lineMarker | :marker | :smooth | :smoothMarker
215
247
  # must be one of "none" | "line" | "lineMarker" | "marker" | "smooth" | "smoothMarker"
216
248
  # @param [Symbol|String] v the value to validate
217
249
  def self.validate_scatter_style(v)
218
- Axlsx::RestrictionValidator.validate "ScatterChart.scatterStyle", [:none, :line, :lineMarker, :marker, :smooth, :smoothMarker], v.to_sym
250
+ Axlsx::RestrictionValidator.validate "ScatterChart.scatterStyle", VALID_SCATTER_STYLE_VALUES, v.to_sym
219
251
  end
220
252
 
253
+ VALID_HORIZONTAL_ALIGNMENT_VALUES = [:general, :left, :center, :right, :fill, :justify, :centerContinuous, :distributed].freeze
254
+
221
255
  # Requires that the value is a valid horizontal_alignment
222
256
  # :general, :left, :center, :right, :fill, :justify, :centerContinuous, :distributed are allowed
223
257
  # @param [Any] v The value validated
224
258
  def self.validate_horizontal_alignment(v)
225
- RestrictionValidator.validate :horizontal_alignment, [:general, :left, :center, :right, :fill, :justify, :centerContinuous, :distributed], v
259
+ RestrictionValidator.validate :horizontal_alignment, VALID_HORIZONTAL_ALIGNMENT_VALUES, v
226
260
  end
227
261
 
262
+ VALID_VERTICAL_ALIGNMENT_VALUES = [:top, :center, :bottom, :justify, :distributed].freeze
263
+
228
264
  # Requires that the value is a valid vertical_alignment
229
265
  # :top, :center, :bottom, :justify, :distributed are allowed
230
266
  # @param [Any] v The value validated
231
267
  def self.validate_vertical_alignment(v)
232
- RestrictionValidator.validate :vertical_alignment, [:top, :center, :bottom, :justify, :distributed], v
268
+ RestrictionValidator.validate :vertical_alignment, VALID_VERTICAL_ALIGNMENT_VALUES, v
233
269
  end
234
270
 
271
+ VALID_CONTENT_TYPE_VALUES = [TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, JPEG_CT, GIF_CT, PNG_CT, DRAWING_CT, COMMENT_CT, VML_DRAWING_CT, PIVOT_TABLE_CT, PIVOT_TABLE_CACHE_DEFINITION_CT].freeze
272
+
235
273
  # Requires that the value is a valid content_type
236
274
  # TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT, COMMENT_CT are allowed
237
275
  # @param [Any] v The value validated
238
276
  def self.validate_content_type(v)
239
- RestrictionValidator.validate :content_type, [TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, JPEG_CT, GIF_CT, PNG_CT, DRAWING_CT, COMMENT_CT, VML_DRAWING_CT, PIVOT_TABLE_CT, PIVOT_TABLE_CACHE_DEFINITION_CT], v
277
+ RestrictionValidator.validate :content_type, VALID_CONTENT_TYPE_VALUES, v
240
278
  end
241
279
 
280
+ VALID_RELATIONSHIP_TYPE_VALUES = [XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R, IMAGE_R, HYPERLINK_R, SHARED_STRINGS_R, COMMENT_R, VML_DRAWING_R, COMMENT_R_NULL, PIVOT_TABLE_R, PIVOT_TABLE_CACHE_DEFINITION_R].freeze
281
+
242
282
  # Requires that the value is a valid relationship_type
243
283
  # XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R, IMAGE_R, HYPERLINK_R, SHARED_STRINGS_R are allowed
244
284
  # @param [Any] v The value validated
245
285
  def self.validate_relationship_type(v)
246
- RestrictionValidator.validate :relationship_type, [XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R, IMAGE_R, HYPERLINK_R, SHARED_STRINGS_R, COMMENT_R, VML_DRAWING_R, COMMENT_R_NULL, PIVOT_TABLE_R, PIVOT_TABLE_CACHE_DEFINITION_R], v
286
+ RestrictionValidator.validate :relationship_type, VALID_RELATIONSHIP_TYPE_VALUES, v
247
287
  end
248
288
 
289
+ VALID_TABLE_ELEMENT_TYPE_VALUES = [:wholeTable, :headerRow, :totalRow, :firstColumn, :lastColumn, :firstRowStripe, :secondRowStripe, :firstColumnStripe, :secondColumnStripe, :firstHeaderCell, :lastHeaderCell, :firstTotalCell, :lastTotalCell, :firstSubtotalColumn, :secondSubtotalColumn, :thirdSubtotalColumn, :firstSubtotalRow, :secondSubtotalRow, :thirdSubtotalRow, :blankRow, :firstColumnSubheading, :secondColumnSubheading, :thirdColumnSubheading, :firstRowSubheading, :secondRowSubheading, :thirdRowSubheading, :pageFieldLabels, :pageFieldValues].freeze
290
+
249
291
  # Requires that the value is a valid table element type
250
292
  # :wholeTable, :headerRow, :totalRow, :firstColumn, :lastColumn, :firstRowStripe, :secondRowStripe, :firstColumnStripe, :secondColumnStripe, :firstHeaderCell, :lastHeaderCell, :firstTotalCell, :lastTotalCell, :firstSubtotalColumn, :secondSubtotalColumn, :thirdSubtotalColumn, :firstSubtotalRow, :secondSubtotalRow, :thirdSubtotalRow, :blankRow, :firstColumnSubheading, :secondColumnSubheading, :thirdColumnSubheading, :firstRowSubheading, :secondRowSubheading, :thirdRowSubheading, :pageFieldLabels, :pageFieldValues are allowed
251
293
  # @param [Any] v The value validated
252
294
  def self.validate_table_element_type(v)
253
- RestrictionValidator.validate :table_element_type, [:wholeTable, :headerRow, :totalRow, :firstColumn, :lastColumn, :firstRowStripe, :secondRowStripe, :firstColumnStripe, :secondColumnStripe, :firstHeaderCell, :lastHeaderCell, :firstTotalCell, :lastTotalCell, :firstSubtotalColumn, :secondSubtotalColumn, :thirdSubtotalColumn, :firstSubtotalRow, :secondSubtotalRow, :thirdSubtotalRow, :blankRow, :firstColumnSubheading, :secondColumnSubheading, :thirdColumnSubheading, :firstRowSubheading, :secondRowSubheading, :thirdRowSubheading, :pageFieldLabels, :pageFieldValues], v
295
+ RestrictionValidator.validate :table_element_type, VALID_TABLE_ELEMENT_TYPE_VALUES, v
254
296
  end
255
297
 
298
+ VALID_DATA_VALIDATION_ERROR_STYLE_VALUES = [:information, :stop, :warning].freeze
299
+
256
300
  # Requires that the value is a valid data_validation_error_style
257
301
  # :information, :stop, :warning
258
302
  # @param [Any] v The value validated
259
303
  def self.validate_data_validation_error_style(v)
260
- RestrictionValidator.validate :validate_data_validation_error_style, [:information, :stop, :warning], v
304
+ RestrictionValidator.validate :validate_data_validation_error_style, VALID_DATA_VALIDATION_ERROR_STYLE_VALUES, v
261
305
  end
262
306
 
307
+ VALID_DATA_VALIDATION_OPERATOR_VALUES = [:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween].freeze
308
+
263
309
  # Requires that the value is valid data validation operator.
264
310
  # valid operators must be one of lessThan, lessThanOrEqual, equal,
265
311
  # notEqual, greaterThanOrEqual, greaterThan, between, notBetween
266
312
  # @param [Any] v The value validated
267
313
  def self.validate_data_validation_operator(v)
268
- RestrictionValidator.validate :data_validation_operator, [:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween], v
314
+ RestrictionValidator.validate :data_validation_operator, VALID_DATA_VALIDATION_OPERATOR_VALUES, v
269
315
  end
270
316
 
317
+ VALID_DATA_VALIDATION_TYPE_VALUES = [:custom, :data, :decimal, :list, :none, :textLength, :date, :time, :whole].freeze
318
+
271
319
  # Requires that the value is valid data validation type.
272
320
  # valid types must be one of custom, data, decimal, list, none, textLength, time, whole
273
321
  # @param [Any] v The value validated
274
322
  def self.validate_data_validation_type(v)
275
- RestrictionValidator.validate :data_validation_type, [:custom, :data, :decimal, :list, :none, :textLength, :date, :time, :whole], v
323
+ RestrictionValidator.validate :data_validation_type, VALID_DATA_VALIDATION_TYPE_VALUES, v
276
324
  end
277
325
 
326
+ VALID_SHEET_VIEW_TYPE_VALUES = [:normal, :page_break_preview, :page_layout].freeze
327
+
278
328
  # Requires that the value is a valid sheet view type.
279
329
  # valid types must be one of normal, page_break_preview, page_layout
280
330
  # @param [Any] v The value validated
281
331
  def self.validate_sheet_view_type(v)
282
- RestrictionValidator.validate :sheet_view_type, [:normal, :page_break_preview, :page_layout], v
332
+ RestrictionValidator.validate :sheet_view_type, VALID_SHEET_VIEW_TYPE_VALUES, v
283
333
  end
284
334
 
335
+ VALID_PANE_TYPE_VALUES = [:bottom_left, :bottom_right, :top_left, :top_right].freeze
336
+
285
337
  # Requires that the value is a valid active pane type.
286
338
  # valid types must be one of bottom_left, bottom_right, top_left, top_right
287
339
  # @param [Any] v The value validated
288
340
  def self.validate_pane_type(v)
289
- RestrictionValidator.validate :active_pane_type, [:bottom_left, :bottom_right, :top_left, :top_right], v
341
+ RestrictionValidator.validate :active_pane_type, VALID_PANE_TYPE_VALUES, v
290
342
  end
291
343
 
344
+ VALID_SPLIT_STATE_TYPE_VALUES = [:frozen, :frozen_split, :split].freeze
345
+
292
346
  # Requires that the value is a valid split state type.
293
347
  # valid types must be one of frozen, frozen_split, split
294
348
  # @param [Any] v The value validated
295
349
  def self.validate_split_state_type(v)
296
- RestrictionValidator.validate :split_state_type, [:frozen, :frozen_split, :split], v
350
+ RestrictionValidator.validate :split_state_type, VALID_SPLIT_STATE_TYPE_VALUES, v
297
351
  end
298
352
 
353
+ VALID_DISPLAY_BLANK_AS_VALUES = [:gap, :span, :zero].freeze
354
+
299
355
  # Requires that the value is a valid "display blanks as" type.
300
356
  # valid types must be one of gap, span, zero
301
357
  # @param [Any] v The value validated
302
358
  def self.validate_display_blanks_as(v)
303
- RestrictionValidator.validate :display_blanks_as, [:gap, :span, :zero], v
359
+ RestrictionValidator.validate :display_blanks_as, VALID_DISPLAY_BLANK_AS_VALUES, v
304
360
  end
305
361
 
362
+ VALID_VIEW_VISIBILITY_VALUES = [:visible, :hidden, :very_hidden].freeze
363
+
306
364
  # Requires that the value is one of :visible, :hidden, :very_hidden
307
365
  def self.validate_view_visibility(v)
308
- RestrictionValidator.validate :visibility, [:visible, :hidden, :very_hidden], v
366
+ RestrictionValidator.validate :visibility, VALID_VIEW_VISIBILITY_VALUES, v
309
367
  end
310
368
 
369
+ VALID_MARKER_SYMBOL_VALUES = [:default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x].freeze
370
+
311
371
  # Requires that the value is one of :default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x
312
372
  def self.validate_marker_symbol(v)
313
- RestrictionValidator.validate :marker_symbol, [:default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x], v
373
+ RestrictionValidator.validate :marker_symbol, VALID_MARKER_SYMBOL_VALUES, v
314
374
  end
315
375
  end