Method: GChart::Axis#validate!
- Defined in:
- lib/gchart/axis.rb
#validate! ⇒ Object
Ensures that all combinations of attributes which have been set will work with each other. Raises ArgumentError otherwise.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/gchart/axis.rb', line 78 def validate! if labels.size > 0 and label_positions.size > 0 and labels.size != label_positions.size raise ArgumentError.new( "Both labels and label_positions have been specified, but their " + "respective counts do not match (labels.size = '#{labels.size}' " + "and label_positions.size = '#{label_positions.size}')" ) end unless label_positions.all? { |pos| pos.is_a?(Numeric) } raise ArgumentError.new( "The label_positions attribute requires numeric values for each position specified" ) end if range unless range.is_a?(Range) raise ArgumentError.new("The range attribute has been specified with a non-Range class") end unless range.first.is_a?(Numeric) raise ArgumentError.new("The range attribute has been specified with non-numeric range values") end end if font_size and not text_color raise ArgumentError.new("To specify a font_size, a text_color must also be specified") end if text_alignment and not (text_color and font_size) raise ArgumentError.new( "To specify a text_alignment, both text_color and font_size must also be specified" ) end if text_color and not GChart.valid_color?(text_color) raise ArgumentError.new("The text_color attribute has been specified with an invalid color") end if font_size and not font_size.is_a?(Numeric) raise ArgumentError.new("The font_size must have a numeric value") end if text_alignment and not TEXT_ALIGNMENT[text_alignment] raise ArgumentError.new( "The text_alignment attribute has been specified with a non-TEXT_ALIGNMENT" ) end if not range_markers.all? { |array| array.is_a?(Array) and array.size == 2 and array[0].is_a?(Range) and array[0].first.is_a?(Numeric) and GChart.valid_color?(array[1]) } raise ArgumentError.new( "The range_markers attribute must be an array of 2-element sub-arrays such that " + "the first element in each sub-array is a Range of numeric values and the second " + "element in each sub-array is a valid color" ) end end |