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
@@ -2,7 +2,7 @@
2
2
  module Axlsx
3
3
  # A border part.
4
4
  class BorderPr
5
-
5
+ include Axlsx::OptionsParser
6
6
  # @return [Color] The color of this border part.
7
7
  attr_reader :color
8
8
 
@@ -45,9 +45,10 @@ module Axlsx
45
45
  # @option options [Symbol] style
46
46
  # @see Axlsx::Border
47
47
  def initialize(options={})
48
- options.each do |o|
49
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
50
- end
48
+ parse_options(options)
49
+ #options.each do |o|
50
+ # self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
51
+ #end
51
52
  end
52
53
 
53
54
  # @see name
@@ -1,9 +1,33 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
+
4
+
3
5
  # CellAlignment stores information about the cell alignment of a style Xf Object.
4
6
  # @note Using Styles#add_style is the recommended way to manage cell alignment.
5
7
  # @see Styles#add_style
6
8
  class CellAlignment
9
+
10
+
11
+ include Axlsx::SerializedAttributes
12
+ include Axlsx::OptionsParser
13
+
14
+ serializable_attributes :horizontal, :vertical, :text_rotation, :wrap_text, :indent, :relative_indent, :justify_last_line, :shrink_to_fit, :reading_order
15
+ # Create a new cell_alignment object
16
+ # @option options [Symbol] horizontal
17
+ # @option options [Symbol] vertical
18
+ # @option options [Integer] text_rotation
19
+ # @option options [Boolean] wrap_text
20
+ # @option options [Integer] indent
21
+ # @option options [Integer] relative_indent
22
+ # @option options [Boolean] justify_last_line
23
+ # @option options [Boolean] shrink_to_fit
24
+ # @option options [Integer] reading_order
25
+ def initialize(options={})
26
+ parse_options options
27
+ end
28
+
29
+
30
+
7
31
  # The horizontal alignment of the cell.
8
32
  # @note
9
33
  # The horizontal cell alignement style must be one of
@@ -31,11 +55,13 @@ module Axlsx
31
55
 
32
56
  # The textRotation of the cell.
33
57
  # @return [Integer]
34
- attr_reader :textRotation
58
+ attr_reader :text_rotation
59
+ alias :textRotation :text_rotation
35
60
 
36
61
  # Indicate if the text of the cell should wrap
37
62
  # @return [Boolean]
38
- attr_reader :wrapText
63
+ attr_reader :wrap_text
64
+ alias :wrapText :wrap_text
39
65
 
40
66
  # The amount of indent
41
67
  # @return [Integer]
@@ -43,64 +69,64 @@ module Axlsx
43
69
 
44
70
  # The amount of relativeIndent
45
71
  # @return [Integer]
46
- attr_reader :relativeIndent
72
+ attr_reader :relative_indent
73
+ alias :relativeIndent :relative_indent
47
74
 
48
75
  # Indicate if the last line should be justified.
49
76
  # @return [Boolean]
50
- attr_reader :justifyLastLine
77
+ attr_reader :justify_last_line
78
+ alias :justifyLastLine :justify_last_line
51
79
 
52
80
  # Indicate if the text should be shrunk to the fit in the cell.
53
81
  # @return [Boolean]
54
- attr_reader :shrinkToFit
82
+ attr_reader :shrink_to_fit
83
+ alias :shrinkToFit :shrink_to_fit
55
84
 
56
85
  # The reading order of the text
57
86
  # 0 Context Dependent
58
87
  # 1 Left-to-Right
59
88
  # 2 Right-to-Left
60
89
  # @return [Integer]
61
- attr_reader :readingOrder
62
-
63
- # Create a new cell_alignment object
64
- # @option options [Symbol] horizontal
65
- # @option options [Symbol] vertical
66
- # @option options [Integer] textRotation
67
- # @option options [Boolean] wrapText
68
- # @option options [Integer] indent
69
- # @option options [Integer] relativeIndent
70
- # @option options [Boolean] justifyLastLine
71
- # @option options [Boolean] shrinkToFit
72
- # @option options [Integer] readingOrder
73
- def initialize(options={})
74
- options.each do |o|
75
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
76
- end
77
- end
90
+ attr_reader :reading_order
91
+ alias :readingOrder :reading_order
78
92
 
79
93
  # @see horizontal
80
94
  def horizontal=(v) Axlsx::validate_horizontal_alignment v; @horizontal = v end
81
95
  # @see vertical
82
96
  def vertical=(v) Axlsx::validate_vertical_alignment v; @vertical = v end
83
97
  # @see textRotation
84
- def textRotation=(v) Axlsx::validate_unsigned_int v; @textRotation = v end
98
+ def text_rotation=(v) Axlsx::validate_unsigned_int v; @text_rotation = v end
99
+ alias :textRotation= :text_rotation=
100
+
85
101
  # @see wrapText
86
- def wrapText=(v) Axlsx::validate_boolean v; @wrapText = v end
102
+ def wrap_text=(v) Axlsx::validate_boolean v; @wrap_text = v end
103
+ alias :wrapText= :wrap_text=
104
+
87
105
  # @see indent
88
106
  def indent=(v) Axlsx::validate_unsigned_int v; @indent = v end
107
+
89
108
  # @see relativeIndent
90
- def relativeIndent=(v) Axlsx::validate_int v; @relativeIndent = v end
109
+ def relative_indent=(v) Axlsx::validate_int v; @relative_indent = v end
110
+ alias :relativeIndent= :relative_indent=
111
+
91
112
  # @see justifyLastLine
92
- def justifyLastLine=(v) Axlsx::validate_boolean v; @justifyLastLine = v end
113
+ def justify_last_line=(v) Axlsx::validate_boolean v; @justify_last_line = v end
114
+ alias :justifyLastLine= :justify_last_line=
115
+
93
116
  # @see shrinkToFit
94
- def shrinkToFit=(v) Axlsx::validate_boolean v; @shrinkToFit = v end
117
+ def shrink_to_fit=(v) Axlsx::validate_boolean v; @shrink_to_fit = v end
118
+ alias :shrinkToFit= :shrink_to_fit=
119
+
95
120
  # @see readingOrder
96
- def readingOrder=(v) Axlsx::validate_unsigned_int v; @readingOrder = v end
121
+ def reading_order=(v) Axlsx::validate_unsigned_int v; @reading_order = v end
122
+ alias :readingOrder= :reading_order=
97
123
 
98
124
  # Serializes the object
99
125
  # @param [String] str
100
126
  # @return [String]
101
127
  def to_xml_string(str = '')
102
128
  str << '<alignment '
103
- str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
129
+ serialized_attributes str
104
130
  str << '/>'
105
131
  end
106
132
 
@@ -5,6 +5,11 @@ module Axlsx
5
5
  # @see Styles#add_style
6
6
  class CellProtection
7
7
 
8
+ include Axlsx::OptionsParser
9
+ include Axlsx::SerializedAttributes
10
+
11
+ serializable_attributes :hidden, :locked
12
+
8
13
  # specifies locking for cells that have the style containing this protection
9
14
  # @return [Boolean]
10
15
  attr_reader :hidden
@@ -17,9 +22,7 @@ module Axlsx
17
22
  # @option options [Boolean] hidden value for hidden protection
18
23
  # @option options [Boolean] locked value for locked protection
19
24
  def initialize(options={})
20
- options.each do |o|
21
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
22
- end
25
+ parse_options options
23
26
  end
24
27
 
25
28
  # @see hidden
@@ -32,7 +35,7 @@ module Axlsx
32
35
  # @return [String]
33
36
  def to_xml_string(str = '')
34
37
  str << '<protection '
35
- str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
38
+ serialized_attributes str
36
39
  str << '/>'
37
40
  end
38
41
 
@@ -4,6 +4,23 @@ module Axlsx
4
4
  # @note Using Styles#add_style is the recommended way to manage cell styling.
5
5
  # @see Styles#add_style
6
6
  class CellStyle
7
+
8
+ include Axlsx::OptionsParser
9
+ include Axlsx::SerializedAttributes
10
+
11
+ # Creats a new CellStyle object
12
+ # @option options [String] name
13
+ # @option options [Integer] xfId
14
+ # @option options [Integer] buildinId
15
+ # @option options [Integer] iLevel
16
+ # @option options [Boolean] hidden
17
+ # @option options [Boolean] customBuiltIn
18
+ def initialize(options={})
19
+ parse_options options
20
+ end
21
+
22
+ serializable_attributes :name, :xfId, :buildinId, :iLevel, :hidden, :customBuilin
23
+
7
24
  # The name of this cell style
8
25
  # @return [String]
9
26
  attr_reader :name
@@ -30,19 +47,7 @@ module Axlsx
30
47
  # @return [Boolean]
31
48
  attr_reader :customBuiltin
32
49
 
33
- # Creats a new CellStyle object
34
- # @option options [String] name
35
- # @option options [Integer] xfId
36
- # @option options [Integer] buildinId
37
- # @option options [Integer] iLevel
38
- # @option options [Boolean] hidden
39
- # @option options [Boolean] customBuiltIn
40
- def initialize(options={})
41
- options.each do |o|
42
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
43
- end
44
- end
45
- # @see name
50
+ # @see name
46
51
  def name=(v) Axlsx::validate_string v; @name = v end
47
52
  # @see xfId
48
53
  def xfId=(v) Axlsx::validate_unsigned_int v; @xfId = v end
@@ -60,7 +65,7 @@ module Axlsx
60
65
  # @return [String]
61
66
  def to_xml_string(str = '')
62
67
  str << '<cellStyle '
63
- str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
68
+ serialized_attributes str
64
69
  str << '/>'
65
70
  end
66
71
 
@@ -2,6 +2,21 @@
2
2
  module Axlsx
3
3
  # The color class represents a color used for borders, fills an fonts
4
4
  class Color
5
+
6
+ include Axlsx::OptionsParser
7
+ include Axlsx::SerializedAttributes
8
+
9
+ # Creates a new Color object
10
+ # @option options [Boolean] auto
11
+ # @option options [String] rgb
12
+ # @option options [Float] tint
13
+ def initialize(options={})
14
+ @rgb = "FF000000"
15
+ parse_options options
16
+ end
17
+
18
+ serializable_attributes :auto, :rgb, :tint
19
+
5
20
  # Determines if the color is system color dependant
6
21
  # @return [Boolean]
7
22
  attr_reader :auto
@@ -31,17 +46,7 @@ module Axlsx
31
46
  # @return [Float]
32
47
  attr_reader :tint
33
48
 
34
- # Creates a new Color object
35
- # @option options [Boolean] auto
36
- # @option options [String] rgb
37
- # @option options [Float] tint
38
- def initialize(options={})
39
- @rgb = "FF000000"
40
- options.each do |o|
41
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
42
- end
43
- end
44
- # @see auto
49
+ # @see auto
45
50
  def auto=(v) Axlsx::validate_boolean v; @auto = v end
46
51
  # @see color
47
52
  def rgb=(v)
@@ -64,11 +69,9 @@ module Axlsx
64
69
  # Serializes the object
65
70
  # @param [String] str
66
71
  # @return [String]
67
- def to_xml_string(str = '')
68
- str << "<color "
69
- self.instance_values.each do |key, value|
70
- str << key.to_s << '="' << value.to_s << '" '
71
- end
72
+ def to_xml_string(str = '', tag_name = 'color')
73
+ str << "<" << tag_name << " "
74
+ serialized_attributes str
72
75
  str << "/>"
73
76
  end
74
77
  end
@@ -3,6 +3,9 @@ module Axlsx
3
3
  # The Dxf class defines an incremental formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style
4
4
  # @see Styles#add_style
5
5
  class Dxf
6
+
7
+ include Axlsx::OptionsParser
8
+
6
9
  # The order in which the child elements is put in the XML seems to
7
10
  # be important for Excel
8
11
  CHILD_ELEMENTS = [:font, :numFmt, :fill, :alignment, :border, :protection]
@@ -42,10 +45,7 @@ module Axlsx
42
45
  # @option options [CellAlignment] alignment
43
46
  # @option options [CellProtection] protection
44
47
  def initialize(options={})
45
- options.each do |o|
46
- next if o[1].nil?
47
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
48
- end
48
+ parse_options options
49
49
  end
50
50
 
51
51
  # @see Dxf#alignment
@@ -4,6 +4,27 @@ module Axlsx
4
4
  # @note The recommended way to manage fonts, and other styles is Styles#add_style
5
5
  # @see Styles#add_style
6
6
  class Font
7
+ include Axlsx::OptionsParser
8
+
9
+ # Creates a new Font
10
+ # @option options [String] name
11
+ # @option options [Integer] charset
12
+ # @option options [Integer] family
13
+ # @option options [Integer] family
14
+ # @option options [Boolean] b
15
+ # @option options [Boolean] i
16
+ # @option options [Boolean] u
17
+ # @option options [Boolean] strike
18
+ # @option options [Boolean] outline
19
+ # @option options [Boolean] shadow
20
+ # @option options [Boolean] condense
21
+ # @option options [Boolean] extend
22
+ # @option options [Color] color
23
+ # @option options [Integer] sz
24
+ def initialize(options={})
25
+ parse_options options
26
+ end
27
+
7
28
  # The name of the font
8
29
  # @return [String]
9
30
  attr_reader :name
@@ -86,28 +107,7 @@ module Axlsx
86
107
  # @return [Integer]
87
108
  attr_reader :sz
88
109
 
89
- # Creates a new Font
90
- # @option options [String] name
91
- # @option options [Integer] charset
92
- # @option options [Integer] family
93
- # @option options [Integer] family
94
- # @option options [Boolean] b
95
- # @option options [Boolean] i
96
- # @option options [Boolean] u
97
- # @option options [Boolean] strike
98
- # @option options [Boolean] outline
99
- # @option options [Boolean] shadow
100
- # @option options [Boolean] condense
101
- # @option options [Boolean] extend
102
- # @option options [Color] color
103
- # @option options [Integer] sz
104
- def initialize(options={})
105
- options.each do |o|
106
- next if o[1].nil?
107
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
108
- end
109
- end
110
- # @see name
110
+ # @see name
111
111
  def name=(v) Axlsx::validate_string v; @name = v end
112
112
  # @see charset
113
113
  def charset=(v) Axlsx::validate_unsigned_int v; @charset = v end
@@ -4,6 +4,24 @@ module Axlsx
4
4
  # @see Open Office XML Part 1 §18.8.24
5
5
  class GradientFill
6
6
 
7
+ include Axlsx::OptionsParser
8
+ include Axlsx::SerializedAttributes
9
+
10
+ # Creates a new GradientFill object
11
+ # @option options [Symbol] type
12
+ # @option options [Float] degree
13
+ # @option options [Float] left
14
+ # @option options [Float] right
15
+ # @option options [Float] top
16
+ # @option options [Float] bottom
17
+ def initialize(options={})
18
+ options[:type] ||= :linear
19
+ parse_options options
20
+ @stop = SimpleTypedList.new GradientStop
21
+ end
22
+
23
+ serializable_attributes :type, :degree, :left, :right, :top, :bottom
24
+
7
25
  # The type of gradient.
8
26
  # @note
9
27
  # valid options are
@@ -36,41 +54,47 @@ module Axlsx
36
54
  # @return [SimpleTypedList]
37
55
  attr_reader :stop
38
56
 
39
- # Creates a new GradientFill object
40
- # @option options [Symbol] type
41
- # @option options [Float] degree
42
- # @option options [Float] left
43
- # @option options [Float] right
44
- # @option options [Float] top
45
- # @option options [Float] bottom
46
- def initialize(options={})
47
- options[:type] ||= :linear
48
- options.each do |o|
49
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
50
- end
51
- @stop = SimpleTypedList.new GradientStop
52
- end
53
-
54
57
  # @see type
55
58
  def type=(v) Axlsx::validate_gradient_type v; @type = v end
59
+
56
60
  # @see degree
57
61
  def degree=(v) Axlsx::validate_float v; @degree = v end
62
+
58
63
  # @see left
59
- def left=(v) DataTypeValidator.validate "GradientFill.left", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @left = v end
64
+ def left=(v)
65
+ validate_format_percentage "GradientFill.left", v
66
+ @left = v
67
+ end
68
+
60
69
  # @see right
61
- def right=(v) DataTypeValidator.validate "GradientFill.right", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @right = v end
70
+ def right=(v)
71
+ validate_format_percentage "GradientFill.right", v
72
+ @right = v
73
+ end
74
+
62
75
  # @see top
63
- def top=(v) DataTypeValidator.validate "GradientFill.top", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @top = v end
76
+ def top=(v)
77
+ validate_format_percentage "GradientFill.top", v
78
+ @top = v
79
+ end
80
+
64
81
  # @see bottom
65
- def bottom=(v) DataTypeValidator.validate "GradientFill.bottom", Float, v, lambda { |arg| arg >= 0.0 && arg <= 1.0}; @bottom= v end
82
+ def bottom=(v)
83
+ validate_format_percentage "GradientFill.bottom", v
84
+ @bottom = v
85
+ end
86
+
87
+ # validates that the value provided is between 0.0 and 1.0
88
+ def validate_format_percentage(name, value)
89
+ DataTypeValidator.validate name, Float, value, lambda { |arg| arg >= 0.0 && arg <= 1.0}
90
+ end
66
91
 
67
92
  # Serializes the object
68
93
  # @param [String] str
69
94
  # @return [String]
70
95
  def to_xml_string(str = '')
71
96
  str << '<gradientFill '
72
- h = self.instance_values.reject { |k,v| k.to_sym == :stop }
73
- str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
97
+ serialized_attributes str
74
98
  str << '>'
75
99
  @stop.each { |s| s.to_xml_string(str) }
76
100
  str << '</gradientFill>'