axlsx 1.3.1 → 1.3.2

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 (99) hide show
  1. data/README.md +13 -5
  2. data/examples/colored_links.rb +59 -0
  3. data/examples/example.rb +421 -266
  4. data/examples/example.xlsx +0 -0
  5. data/examples/example_streamed.xlsx +0 -0
  6. data/examples/finance.rb +82 -0
  7. data/examples/finance.xlsx +0 -0
  8. data/examples/financial.xlsx +0 -0
  9. data/examples/no-use_autowidth.xlsx +0 -0
  10. data/examples/shared_strings_example.xlsx +0 -0
  11. data/examples/where_is_my_color.xlsx +0 -0
  12. data/lib/axlsx.rb +11 -4
  13. data/lib/axlsx/content_type/abstract_content_type.rb +32 -0
  14. data/lib/axlsx/content_type/content_type.rb +1 -1
  15. data/lib/axlsx/content_type/default.rb +6 -37
  16. data/lib/axlsx/content_type/override.rb +6 -38
  17. data/lib/axlsx/doc_props/app.rb +7 -4
  18. data/lib/axlsx/drawing/axis.rb +3 -3
  19. data/lib/axlsx/drawing/chart.rb +2 -3
  20. data/lib/axlsx/drawing/d_lbls.rb +21 -31
  21. data/lib/axlsx/drawing/drawing.rb +6 -0
  22. data/lib/axlsx/drawing/hyperlink.rb +40 -32
  23. data/lib/axlsx/drawing/marker.rb +13 -13
  24. data/lib/axlsx/drawing/num_data.rb +6 -6
  25. data/lib/axlsx/drawing/num_data_source.rb +17 -16
  26. data/lib/axlsx/drawing/one_cell_anchor.rb +20 -22
  27. data/lib/axlsx/drawing/pic.rb +25 -27
  28. data/lib/axlsx/drawing/picture_locking.rb +12 -44
  29. data/lib/axlsx/drawing/scaling.rb +13 -13
  30. data/lib/axlsx/drawing/scatter_chart.rb +3 -3
  31. data/lib/axlsx/drawing/series.rb +3 -6
  32. data/lib/axlsx/drawing/str_data.rb +3 -3
  33. data/lib/axlsx/drawing/str_val.rb +7 -8
  34. data/lib/axlsx/drawing/view_3D.rb +51 -37
  35. data/lib/axlsx/drawing/vml_shape.rb +23 -23
  36. data/lib/axlsx/package.rb +14 -16
  37. data/lib/axlsx/stylesheet/border.rb +29 -20
  38. data/lib/axlsx/stylesheet/border_pr.rb +5 -4
  39. data/lib/axlsx/stylesheet/cell_alignment.rb +55 -29
  40. data/lib/axlsx/stylesheet/cell_protection.rb +7 -4
  41. data/lib/axlsx/stylesheet/cell_style.rb +19 -14
  42. data/lib/axlsx/stylesheet/color.rb +19 -16
  43. data/lib/axlsx/stylesheet/dxf.rb +4 -4
  44. data/lib/axlsx/stylesheet/font.rb +22 -22
  45. data/lib/axlsx/stylesheet/gradient_fill.rb +45 -21
  46. data/lib/axlsx/stylesheet/num_fmt.rb +22 -13
  47. data/lib/axlsx/stylesheet/pattern_fill.rb +12 -21
  48. data/lib/axlsx/stylesheet/styles.rb +1 -1
  49. data/lib/axlsx/stylesheet/table_style.rb +17 -16
  50. data/lib/axlsx/stylesheet/table_style_element.rb +15 -11
  51. data/lib/axlsx/stylesheet/table_styles.rb +14 -11
  52. data/lib/axlsx/stylesheet/xf.rb +28 -26
  53. data/lib/axlsx/util/accessors.rb +49 -0
  54. data/lib/axlsx/util/options_parser.rb +15 -0
  55. data/lib/axlsx/util/serialized_attributes.rb +46 -0
  56. data/lib/axlsx/util/simple_typed_list.rb +16 -4
  57. data/lib/axlsx/version.rb +1 -1
  58. data/lib/axlsx/workbook/defined_name.rb +13 -58
  59. data/lib/axlsx/workbook/workbook.rb +27 -1
  60. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +11 -19
  61. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +20 -27
  62. data/lib/axlsx/workbook/worksheet/cell.rb +38 -39
  63. data/lib/axlsx/workbook/worksheet/cfvo.rb +15 -15
  64. data/lib/axlsx/workbook/worksheet/cfvos.rb +18 -0
  65. data/lib/axlsx/workbook/worksheet/col.rb +34 -27
  66. data/lib/axlsx/workbook/worksheet/color_scale.rb +7 -13
  67. data/lib/axlsx/workbook/worksheet/comment.rb +14 -11
  68. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +11 -11
  69. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +27 -25
  70. data/lib/axlsx/workbook/worksheet/data_bar.rb +44 -34
  71. data/lib/axlsx/workbook/worksheet/data_validation.rb +61 -62
  72. data/lib/axlsx/workbook/worksheet/dimension.rb +0 -1
  73. data/lib/axlsx/workbook/worksheet/icon_set.rb +20 -20
  74. data/lib/axlsx/workbook/worksheet/page_margins.rb +21 -19
  75. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +6 -9
  76. data/lib/axlsx/workbook/worksheet/page_setup.rb +20 -19
  77. data/lib/axlsx/workbook/worksheet/pane.rb +48 -51
  78. data/lib/axlsx/workbook/worksheet/print_options.rb +8 -30
  79. data/lib/axlsx/workbook/worksheet/protected_range.rb +16 -13
  80. data/lib/axlsx/workbook/worksheet/selection.rb +30 -38
  81. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +6 -26
  82. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +19 -57
  83. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +51 -155
  84. data/lib/axlsx/workbook/worksheet/sheet_view.rb +68 -234
  85. data/lib/axlsx/workbook/worksheet/table.rb +16 -18
  86. data/lib/axlsx/workbook/worksheet/table_style_info.rb +10 -27
  87. data/lib/axlsx/workbook/worksheet/worksheet.rb +6 -7
  88. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  89. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +11 -33
  90. data/test/content_type/tc_default.rb +0 -11
  91. data/test/content_type/tc_override.rb +0 -13
  92. data/test/drawing/tc_d_lbls.rb +14 -4
  93. data/test/tc_axlsx.rb +20 -2
  94. data/test/workbook/tc_defined_name.rb +2 -2
  95. data/test/workbook/tc_workbook.rb +15 -0
  96. data/test/workbook/worksheet/tc_col.rb +11 -1
  97. data/test/workbook/worksheet/tc_pane.rb +5 -45
  98. data/test/workbook/worksheet/tc_selection.rb +9 -48
  99. metadata +13 -3
@@ -8,35 +8,36 @@ module Axlsx
8
8
  #
9
9
  class Cfvo
10
10
 
11
+ include Axlsx::OptionsParser
12
+ include Axlsx::SerializedAttributes
13
+
14
+ # Creates a new Cfvo object
15
+ # @option options [Symbol] type The type of conditional formatting value object
16
+ # @option options [Boolean] gte threshold value usage indicator
17
+ # @option options [String] val The value of the conditional formatting object
18
+ def initialize(options={})
19
+ @gte = true
20
+ parse_options options
21
+ end
22
+
23
+ serializable_attributes :type, :gte, :val
24
+
11
25
  # Type (ST_CfvoType)
12
26
  # The type of this conditional formatting value object. options are num, percent, max, min, formula and percentile
13
27
  # @return [Symbol]
14
28
  attr_reader :type
15
29
 
16
-
17
30
  # Type (xsd:boolean)
18
31
  # For icon sets, determines whether this threshold value uses the greater than or equal to operator. 0 indicates 'greater than' is used instead of 'greater than or equal to'.
19
32
  # The default value is true
20
33
  # @return [Boolean]
21
34
  attr_reader :gte
22
35
 
23
-
24
36
  # Type (ST_Xstring)
25
37
  # The value of the conditional formatting object
26
38
  # This library will accept any value so long as it supports to_s
27
39
  attr_reader :val
28
40
 
29
- # Creates a new Cfvo object
30
- # @option options [Symbol] type The type of conditional formatting value object
31
- # @option options [Boolean] gte threshold value usage indicator
32
- # @option options [String] val The value of the conditional formatting object
33
- def initialize(options={})
34
- @gte = true
35
- options.each do |o|
36
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
37
- end
38
- end
39
-
40
41
  # @see type
41
42
  def type=(v); Axlsx::validate_conditional_formatting_value_object_type(v); @type = v end
42
43
 
@@ -54,9 +55,8 @@ module Axlsx
54
55
  # @return [String]
55
56
  def to_xml_string(str = '')
56
57
  str << '<cfvo '
57
- str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' }.join(' ')
58
+ serialized_attributes str
58
59
  str << ' />'
59
60
  end
60
-
61
61
  end
62
62
  end
@@ -0,0 +1,18 @@
1
+ module Axlsx
2
+
3
+ #A collection of Cfvo objects that initializes with the required
4
+ #first two items
5
+ class Cfvos < SimpleTypedList
6
+
7
+ def initialize
8
+ super(Cfvo)
9
+ @list << Cfvo.new(:type => :min, :val => 0)
10
+ @list << Cfvo.new(:type => :max, :val => 0)
11
+ lock
12
+ end
13
+
14
+ def to_xml_string(str='')
15
+ @list.each { |cfvo| cfvo.to_xml_string(str) }
16
+ end
17
+ end
18
+ end
@@ -4,6 +4,27 @@ module Axlsx
4
4
  # The Col class defines column attributes for columns in sheets.
5
5
  class Col
6
6
 
7
+ include Axlsx::OptionsParser
8
+ include Axlsx::SerializedAttributes
9
+ # Create a new Col objects
10
+ # @param min First column affected by this 'column info' record.
11
+ # @param max Last column affected by this 'column info' record.
12
+ # @option options [Boolean] collapsed see Col#collapsed
13
+ # @option options [Boolean] hidden see Col#hidden
14
+ # @option options [Boolean] outlineLevel see Col#outlineLevel
15
+ # @option options [Boolean] phonetic see Col#phonetic
16
+ # @option options [Integer] style see Col#style
17
+ # @option options [Numeric] width see Col#width
18
+ def initialize(min, max, options={})
19
+ Axlsx.validate_unsigned_int(max)
20
+ Axlsx.validate_unsigned_int(min)
21
+ @min = min
22
+ @max = max
23
+ parse_options options
24
+ end
25
+
26
+ serializable_attributes :collapsed, :hidden, :outline_level, :phonetic, :style, :width, :min, :max, :best_fit, :custom_width
27
+
7
28
  # First column affected by this 'column info' record.
8
29
  # @return [Integer]
9
30
  attr_reader :min
@@ -17,7 +38,8 @@ module Axlsx
17
38
  # 'Best fit' means that when numbers are typed into a cell contained in a 'best fit' column, the column width should
18
39
  # automatically resize to display the number. [Note: In best fit cases, column width must not be made smaller, only larger. end note]
19
40
  # @return [Boolean]
20
- attr_reader :bestFit
41
+ attr_reader :best_fit
42
+ alias :bestFit :best_fit
21
43
 
22
44
  # Flag indicating if the outlining of the affected column(s) is in the collapsed state.
23
45
  # @return [Boolean]
@@ -29,7 +51,8 @@ module Axlsx
29
51
 
30
52
  # Outline level of affected column(s). Range is 0 to 7.
31
53
  # @return [Integer]
32
- attr_reader :outlineLevel
54
+ attr_reader :outline_level
55
+ alias :outlineLevel :outline_level
33
56
 
34
57
  # Flag indicating if the phonetic information should be displayed by default for the affected column(s) of the worksheet.
35
58
  # @return [Boolean]
@@ -44,7 +67,8 @@ module Axlsx
44
67
  attr_reader :width
45
68
 
46
69
  # @return [Boolean]
47
- attr_reader :customWidth
70
+ attr_reader :custom_width
71
+ alias :customWidth :custom_width
48
72
 
49
73
  # @see Col#collapsed
50
74
  def collapsed=(v)
@@ -59,11 +83,12 @@ module Axlsx
59
83
  end
60
84
 
61
85
  # @see Col#outline
62
- def outlineLevel=(v)
86
+ def outline_level=(v)
63
87
  Axlsx.validate_unsigned_numeric(v)
64
88
  raise ArgumentError, 'outlineLevel must be between 0 and 7' unless 0 <= v && v <= 7
65
- @outlineLevel = v
89
+ @outline_level = v
66
90
  end
91
+ alias :outlineLevel= :outline_level=
67
92
 
68
93
  # @see Col#phonetic
69
94
  def phonetic=(v)
@@ -80,29 +105,10 @@ module Axlsx
80
105
  # @see Col#width
81
106
  def width=(v)
82
107
  Axlsx.validate_unsigned_numeric(v) unless v == nil
83
- @customWidth = @bestFit = v != nil
108
+ @custom_width = @best_fit = v != nil
84
109
  @width = v
85
110
  end
86
111
 
87
- # Create a new Col objects
88
- # @param min First column affected by this 'column info' record.
89
- # @param max Last column affected by this 'column info' record.
90
- # @option options [Boolean] collapsed see Col#collapsed
91
- # @option options [Boolean] hidden see Col#hidden
92
- # @option options [Boolean] outlineLevel see Col#outlineLevel
93
- # @option options [Boolean] phonetic see Col#phonetic
94
- # @option options [Integer] style see Col#style
95
- # @option options [Numeric] width see Col#width
96
- def initialize(min, max, options={})
97
- Axlsx.validate_unsigned_int(max)
98
- Axlsx.validate_unsigned_int(min)
99
- @min = min
100
- @max = max
101
- options.each do |o|
102
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
103
- end
104
- end
105
-
106
112
  # updates the width for this col based on the cells autowidth and
107
113
  # an optionally specified fixed width
108
114
  # @param [Cell] cell The cell to use in updating this col's width
@@ -122,8 +128,9 @@ module Axlsx
122
128
  # @param [String] str
123
129
  # @return [String]
124
130
  def to_xml_string(str = '')
125
- attrs = self.instance_values.reject{ |key, value| value == nil }
126
- str << '<col ' << attrs.map { |key, value| '' << key << '="' << value.to_s << '"' }.join(' ') << '/>'
131
+ str << '<col '
132
+ serialized_attributes str
133
+ str << '/>'
127
134
  end
128
135
 
129
136
  end
@@ -10,7 +10,9 @@ module Axlsx
10
10
  # A simple typed list of cfvos
11
11
  # @return [SimpleTypedList]
12
12
  # @see Cfvo
13
- attr_reader :value_objects
13
+ def value_objects
14
+ @value_objects ||= Cfvos.new
15
+ end
14
16
 
15
17
  # A simple types list of colors
16
18
  # @return [SimpleTypedList]
@@ -23,7 +25,6 @@ module Axlsx
23
25
  # @see Cfvo
24
26
  # @see Color
25
27
  def initialize
26
- initialize_value_objects
27
28
  initialize_colors
28
29
  yield self if block_given?
29
30
  end
@@ -32,9 +33,9 @@ module Axlsx
32
33
  # a reference to the newly created cfvo and color objects so you can alter the default properties.
33
34
  # @return [Hash] a hash with :cfvo and :color keys referencing the newly added objects.
34
35
  def add(options={})
35
- @value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0)
36
+ value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0)
36
37
  @colors << Color.new(:rgb => options[:color] || "FF000000")
37
- {:cfvo => @value_objects.last, :color => @colors.last}
38
+ {:cfvo => value_objects.last, :color => @colors.last}
38
39
  end
39
40
 
40
41
 
@@ -42,7 +43,7 @@ module Axlsx
42
43
  # @param [Integer] index The index of the cfvo and color object to delete
43
44
  # @note you cannot remove the first two cfvo and color pairs
44
45
  def delete_at(index=2)
45
- @value_objects.delete_at index
46
+ value_objects.delete_at index
46
47
  @colors.delete_at index
47
48
  end
48
49
 
@@ -51,20 +52,13 @@ module Axlsx
51
52
  # @return [String]
52
53
  def to_xml_string(str = '')
53
54
  str << '<colorScale>'
54
- @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
55
+ value_objects.to_xml_string(str)
55
56
  @colors.each { |color| color.to_xml_string(str) }
56
57
  str << '</colorScale>'
57
58
  end
58
59
 
59
60
  private
60
61
 
61
- # creates the initial cfvo objects
62
- def initialize_value_objects
63
- @value_objects = SimpleTypedList.new Cfvo
64
- @value_objects.concat [Cfvo.new(:type => :min, :val => 0), Cfvo.new(:type => :max, :val => 0)]
65
- @value_objects.lock
66
- end
67
-
68
62
  # creates the initial color objects
69
63
  def initialize_colors
70
64
  @colors = SimpleTypedList.new Color
@@ -3,6 +3,20 @@ module Axlsx
3
3
  # A comment is the text data for a comment
4
4
  class Comment
5
5
 
6
+ include Axlsx::OptionsParser
7
+
8
+ # Creates a new comment object
9
+ # @param [Comments] comments
10
+ # @param [Hash] options
11
+ # @option [String] author the author of the comment
12
+ # @option [String] text The text for the comment
13
+ def initialize(comments, options={})
14
+ raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
15
+ @comments = comments
16
+ parse_options options
17
+ yield self if block_given?
18
+ end
19
+
6
20
  # The text to render
7
21
  # @return [String]
8
22
  attr_reader :text
@@ -26,22 +40,12 @@ module Axlsx
26
40
  # rPh (Phonetic Text Run)
27
41
  # phoneticPr (Phonetic Properties)
28
42
 
29
- def initialize(comments, options={})
30
- raise ArgumentError, "A comment needs a parent comments object" unless comments.is_a?(Comments)
31
- @comments = comments
32
- options.each do |o|
33
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
34
- end
35
- yield self if block_given?
36
- end
37
-
38
43
  # The vml shape that will render this comment
39
44
  # @return [VmlShape]
40
45
  def vml_shape
41
46
  @vml_shape ||= initialize_vml_shape
42
47
  end
43
48
 
44
- #
45
49
  # The index of this author in a unique sorted list of all authors in
46
50
  # the comment.
47
51
  # @return [Integer]
@@ -96,6 +100,5 @@ module Axlsx
96
100
  vml.bottom_row = vml.row + 4
97
101
  end
98
102
  end
99
-
100
103
  end
101
104
  end
@@ -6,6 +6,16 @@ module Axlsx
6
6
  # @see ConditionalFormattingRule
7
7
  class ConditionalFormatting
8
8
 
9
+ include Axlsx::OptionsParser
10
+
11
+ # Creates a new {ConditionalFormatting} object
12
+ # @option options [Array] rules The rules to apply
13
+ # @option options [String] sqref The range to apply the rules to
14
+ def initialize(options={})
15
+ @rules = []
16
+ parse_options options
17
+ end
18
+
9
19
  # Range over which the formatting is applied, in "A1:B2" format
10
20
  # @return [String]
11
21
  attr_reader :sqref
@@ -18,17 +28,7 @@ module Axlsx
18
28
  # @return [Array]
19
29
  attr_reader :rules
20
30
 
21
- # Creates a new {ConditionalFormatting} object
22
- # @option options [Array] rules The rules to apply
23
- # @option options [String] sqref The range to apply the rules to
24
- def initialize(options={})
25
- @rules = []
26
- options.each do |o|
27
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
28
- end
29
- end
30
-
31
- # Add Conditional Formatting Rules to this object. Rules can either
31
+ # Add Conditional Formatting Rules to this object. Rules can either
32
32
  # be already created {ConditionalFormattingRule} elements or
33
33
  # hashes of options for automatic creation. If rules is a hash
34
34
  # instead of an array, assume only one rule being added.
@@ -8,8 +8,32 @@ module Axlsx
8
8
  # @see ConditionalFormattingRule#initialize
9
9
  class ConditionalFormattingRule
10
10
 
11
- # instance values that must be serialized as their own elements - e.g. not attributes.
12
- CHILD_ELEMENTS = [:formula, :color_scale, :data_bar, :icon_set]
11
+ include Axlsx::OptionsParser
12
+ include Axlsx::SerializedAttributes
13
+
14
+ # Creates a new Conditional Formatting Rule object
15
+ # @option options [Symbol] type The type of this formatting rule
16
+ # @option options [Boolean] aboveAverage This is an aboveAverage rule
17
+ # @option options [Boolean] bottom This is a bottom N rule.
18
+ # @option options [Integer] dxfId The formatting id to apply to matches
19
+ # @option options [Boolean] equalAverage Is the aboveAverage or belowAverage rule inclusive
20
+ # @option options [Integer] priority The priority of the rule, 1 is highest
21
+ # @option options [Symbol] operator Which operator to apply
22
+ # @option options [String] text The value to apply a text operator against
23
+ # @option options [Boolean] percent If a top/bottom N rule, evaluate as N% rather than N
24
+ # @option options [Integer] rank If a top/bottom N rule, the value of N
25
+ # @option options [Integer] stdDev The number of standard deviations above or below the average to match
26
+ # @option options [Boolean] stopIfTrue Stop evaluating rules after this rule matches
27
+ # @option options [Symbol] timePeriod The time period in a date occuring... rule
28
+ # @option options [String] formula The formula to match against in i.e. an equal rule
29
+ def initialize(options={})
30
+ @color_scale = @data_bar = @icon_set = @formula = nil
31
+ parse_options options
32
+ end
33
+
34
+ serializable_attributes :type, :aboveAverage, :bottom, :dxfId, :equalAverage,
35
+ :priority, :operator, :text, :percent, :rank, :stdDev,
36
+ :stopIfTrue, :timePeriod
13
37
 
14
38
  # Formula
15
39
  # @return [String]
@@ -129,28 +153,6 @@ module Axlsx
129
153
  @icon_set ||= IconSet.new
130
154
  end
131
155
 
132
- # Creates a new Conditional Formatting Rule object
133
- # @option options [Symbol] type The type of this formatting rule
134
- # @option options [Boolean] aboveAverage This is an aboveAverage rule
135
- # @option options [Boolean] bottom This is a bottom N rule.
136
- # @option options [Integer] dxfId The formatting id to apply to matches
137
- # @option options [Boolean] equalAverage Is the aboveAverage or belowAverage rule inclusive
138
- # @option options [Integer] priority The priority of the rule, 1 is highest
139
- # @option options [Symbol] operator Which operator to apply
140
- # @option options [String] text The value to apply a text operator against
141
- # @option options [Boolean] percent If a top/bottom N rule, evaluate as N% rather than N
142
- # @option options [Integer] rank If a top/bottom N rule, the value of N
143
- # @option options [Integer] stdDev The number of standard deviations above or below the average to match
144
- # @option options [Boolean] stopIfTrue Stop evaluating rules after this rule matches
145
- # @option options [Symbol] timePeriod The time period in a date occuring... rule
146
- # @option options [String] formula The formula to match against in i.e. an equal rule
147
- def initialize(options={})
148
- @color_scale = @data_bar = @icon_set = @formula = nil
149
- options.each do |o|
150
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
151
- end
152
- end
153
-
154
156
  # @see type
155
157
  def type=(v); Axlsx::validate_conditional_formatting_type(v); @type = v end
156
158
  # @see aboveAverage
@@ -204,7 +206,7 @@ module Axlsx
204
206
  # @return [String]
205
207
  def to_xml_string(str = '')
206
208
  str << '<cfRule '
207
- str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ')
209
+ serialized_attributes str
208
210
  str << '>'
209
211
  str << '<formula>' << self.formula << '</formula>' if @formula
210
212
  @color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
@@ -7,6 +7,24 @@ module Axlsx
7
7
  # @see ConditionalFormattingRule#initialize
8
8
  class DataBar
9
9
 
10
+ include Axlsx::OptionsParser
11
+ include Axlsx::SerializedAttributes
12
+
13
+ # Creates a new data bar conditional formatting object
14
+ # @option options [Integer] minLength
15
+ # @option options [Integer] maxLength
16
+ # @option options [Boolean] showValue
17
+ # @option options [String] color - the rbg value used to color the bars
18
+ def initialize(options = {})
19
+ @min_length = 10
20
+ @max_length = 90
21
+ @show_value = true
22
+ parse_options options
23
+ yield self if block_given?
24
+ end
25
+
26
+ serializable_attributes :min_length, :max_length, :show_value
27
+
10
28
  # instance values that must be serialized as their own elements - e.g. not attributes.
11
29
  CHILD_ELEMENTS = [:value_objects, :color]
12
30
 
@@ -14,24 +32,29 @@ module Axlsx
14
32
  # The minimum length of the data bar, as a percentage of the cell width.
15
33
  # The default value is 10
16
34
  # @return [Integer]
17
- attr_reader :minLength
35
+ attr_reader :min_length
36
+ alias :minLength :min_length
18
37
 
19
38
  # maxLength attribute
20
39
  # The maximum length of the data bar, as a percentage of the cell width.
21
40
  # The default value is 90
22
41
  # @return [Integer]
23
- attr_reader :maxLength
42
+ attr_reader :max_length
43
+ alias :maxLength :max_length
24
44
 
25
45
  # maxLength attribute
26
46
  # Indicates whether to show the values of the cells on which this data bar is applied.
27
47
  # The default value is true
28
48
  # @return [Boolean]
29
- attr_reader :showValue
49
+ attr_reader :show_value
50
+ alias :showValue :show_value
30
51
 
31
52
  # A simple typed list of cfvos
32
53
  # @return [SimpleTypedList]
33
54
  # @see Cfvo
34
- attr_reader :value_objects
55
+ def value_objects
56
+ @value_objects ||= Cfvos.new
57
+ end
35
58
 
36
59
  # color
37
60
  # the color object used in the data bar formatting
@@ -40,29 +63,26 @@ module Axlsx
40
63
  @color ||= Color.new :rgb => "FF0000FF"
41
64
  end
42
65
 
43
- # Creates a new data bar conditional formatting object
44
- # @option options [Integer] minLength
45
- # @option options [Integer] maxLength
46
- # @option options [Boolean] showValue
47
- # @option options [String] color - the rbg value used to color the bars
48
- def initialize(options = {})
49
- @minLength = 10
50
- @maxLength = 90
51
- @showValue = true
52
- initialize_value_objects
53
- options.each do |o|
54
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
55
- end
56
- yield self if block_given?
66
+ # @see minLength
67
+ def min_length=(v)
68
+ Axlsx.validate_unsigned_int(v)
69
+ @min_length = v
57
70
  end
71
+ alias :minLength= :min_length=
58
72
 
59
- # @see minLength
60
- def minLength=(v); Axlsx.validate_unsigned_int(v); @minLength = v end
61
73
  # @see maxLength
62
- def maxLength=(v); Axlsx.validate_unsigned_int(v); @maxLength = v end
74
+ def max_length=(v)
75
+ Axlsx.validate_unsigned_int(v)
76
+ @max_length = v
77
+ end
78
+ alias :maxLength= :max_length=
63
79
 
64
80
  # @see showValue
65
- def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
81
+ def show_value=(v)
82
+ Axlsx.validate_boolean(v)
83
+ @show_value = v
84
+ end
85
+ alias :showValue= :show_value=
66
86
 
67
87
  # Sets the color for the data bars.
68
88
  # @param [Color|String] v The color object, or rgb string value to apply
@@ -77,21 +97,11 @@ module Axlsx
77
97
  # @return [String]
78
98
  def to_xml_string(str="")
79
99
  str << '<dataBar '
80
- str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ')
100
+ serialized_attributes str
81
101
  str << '>'
82
- @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
102
+ value_objects.to_xml_string(str)
83
103
  self.color.to_xml_string(str)
84
104
  str << '</dataBar>'
85
105
  end
86
-
87
- private
88
-
89
- # Initalize the simple typed list of value objects
90
- # I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do.
91
- def initialize_value_objects
92
- @value_objects = SimpleTypedList.new Cfvo
93
- @value_objects.concat [Cfvo.new(:type => :min, :val => 0), Cfvo.new(:type => :max, :val => 0)]
94
- @value_objects.lock
95
- end
96
106
  end
97
107
  end