Class: Writexlsx::Worksheet::DataValidation
- Inherits:
-
Object
- Object
- Writexlsx::Worksheet::DataValidation
- Defined in:
- lib/write_xlsx/worksheet/data_validation.rb
Overview
:nodoc:
Constant Summary
Constants included from Constants
Constants::COL_MAX, Constants::ROW_MAX, Constants::SHEETNAME_MAX, Constants::STR_MAX
Constants included from Utility::Common
Utility::Common::PERL_TRUE_VALUES
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
-
#criteria ⇒ Object
readonly
Returns the value of attribute criteria.
-
#dropdown ⇒ Object
readonly
Returns the value of attribute dropdown.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#error_title ⇒ Object
readonly
Returns the value of attribute error_title.
-
#error_type ⇒ Object
readonly
Returns the value of attribute error_type.
-
#ignore_blank ⇒ Object
readonly
Returns the value of attribute ignore_blank.
-
#input_message ⇒ Object
readonly
Returns the value of attribute input_message.
-
#input_title ⇒ Object
readonly
Returns the value of attribute input_title.
-
#maximum ⇒ Object
readonly
Returns the value of attribute maximum.
-
#minimum ⇒ Object
readonly
Returns the value of attribute minimum.
-
#other_cells ⇒ Object
readonly
Returns the value of attribute other_cells.
-
#show_error ⇒ Object
readonly
Returns the value of attribute show_error.
-
#show_input ⇒ Object
readonly
Returns the value of attribute show_input.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#validate ⇒ Object
readonly
Returns the value of attribute validate.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(*args) ⇒ DataValidation
constructor
A new instance of DataValidation.
- #keys ⇒ Object
- #options_to_instance_variable(params) ⇒ Object
- #validate_none? ⇒ Boolean
-
#write_data_validation(writer) ⇒ Object
Write the
element.
Methods included from Utility::DateTime
Methods included from Utility::Dimensions
#check_dimensions, #check_dimensions_and_update_max_min_values, #store_col_max_min_values, #store_row_max_min_values
Methods included from Utility::CellReference
#row_col_notation, #substitute_cellref, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell
Methods included from Utility::Common
#absolute_char, #check_parameter, #float_to_str, #ptrue?, #put_deprecate_message
Constructor Details
#initialize(*args) ⇒ DataValidation
Returns a new instance of DataValidation.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 22 def initialize(*args) # Check for a cell reference in A1 notation and substitute row and column. if (row_col_array = row_col_notation(args.first)) case row_col_array.size when 2 row1, col1 = row_col_array row2, col2, = args[1..-1] when 4 row1, col1, row2, col2 = row_col_array = args[1] end else row1, col1, row2, col2, = args end if row2.respond_to?(:keys) (row2.dup) row2 = row1 col2 = col1 elsif .respond_to?(:keys) (.dup) else raise WriteXLSXInsufficientArgumentError end raise WriteXLSXInsufficientArgumentError if [row1, col1, row2, col2].include?(nil) check_for_valid_input_params check_dimensions(row1, col1) check_dimensions(row2, col2) @cells = [[row1, col1, row2, col2]] @value = @source if @source @value = @minimum if @minimum @validate = valid_validation_type[@validate.downcase] # No action is required for validate type 'any' # unless there are input messages. if @validate == 'none' && !@input_message && !@input_title @validate_none = true return end # The any, list and custom validations don't have a criteria # so we use a default of 'between' if %w[none list custom].include?(@validate) @criteria = 'between' @maximum = nil end check_criteria_required check_valid_citeria_types @criteria = valid_criteria_type[@criteria.downcase] check_maximum_value_when_criteria_is_between_or_notbetween @error_type = has_key?(:error_type) ? error_type_hash[@error_type.downcase] : 0 convert_date_time_value_if_required # Check that the input title doesn't exceed the maximum length. raise "Length of input title '#{@input_title}' exceeds Excel's limit of 32" if @input_title && @input_title.length > 32 # Check that the input message doesn't exceed the maximum length. raise "Length of input message '#{@input_message}' exceeds Excel's limit of 255" if @input_message && @input_message.length > 255 set_some_defaults # A (for now) undocumented parameter to pass additional cell ranges. @other_cells.each { |cells| @cells << cells } if has_key?(:other_cells) end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
18 19 20 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 18 def cells @cells end |
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
17 18 19 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 17 def criteria @criteria end |
#dropdown ⇒ Object (readonly)
Returns the value of attribute dropdown.
19 20 21 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 19 def dropdown @dropdown end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
20 21 22 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 20 def @error_message end |
#error_title ⇒ Object (readonly)
Returns the value of attribute error_title.
20 21 22 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 20 def error_title @error_title end |
#error_type ⇒ Object (readonly)
Returns the value of attribute error_type.
18 19 20 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 18 def error_type @error_type end |
#ignore_blank ⇒ Object (readonly)
Returns the value of attribute ignore_blank.
19 20 21 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 19 def ignore_blank @ignore_blank end |
#input_message ⇒ Object (readonly)
Returns the value of attribute input_message.
20 21 22 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 20 def @input_message end |
#input_title ⇒ Object (readonly)
Returns the value of attribute input_title.
20 21 22 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 20 def input_title @input_title end |
#maximum ⇒ Object (readonly)
Returns the value of attribute maximum.
17 18 19 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 17 def maximum @maximum end |
#minimum ⇒ Object (readonly)
Returns the value of attribute minimum.
17 18 19 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 17 def minimum @minimum end |
#other_cells ⇒ Object (readonly)
Returns the value of attribute other_cells.
18 19 20 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 18 def other_cells @other_cells end |
#show_error ⇒ Object (readonly)
Returns the value of attribute show_error.
19 20 21 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 19 def show_error @show_error end |
#show_input ⇒ Object (readonly)
Returns the value of attribute show_input.
19 20 21 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 19 def show_input @show_input end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
17 18 19 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 17 def source @source end |
#validate ⇒ Object (readonly)
Returns the value of attribute validate.
17 18 19 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 17 def validate @validate end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
17 18 19 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 17 def value @value end |
Instance Method Details
#keys ⇒ Object
98 99 100 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 98 def keys instance_variables.collect { |v| v.to_s.sub(/@/, '').to_sym } end |
#options_to_instance_variable(params) ⇒ Object
92 93 94 95 96 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 92 def (params) params.each do |k, v| instance_variable_set("@#{k}", v) end end |
#validate_none? ⇒ Boolean
102 103 104 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 102 def validate_none? @validate_none end |
#write_data_validation(writer) ⇒ Object
Write the
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 109 def write_data_validation(writer) # :nodoc: @writer = writer if @validate == 'none' @writer.empty_tag('dataValidation', attributes) else @writer.tag_elements('dataValidation', attributes) do # Write the formula1 element. write_formula_1(@value) # Write the formula2 element. write_formula_2(@maximum) if @maximum end end end |