Class: Writexlsx::Worksheet::DataValidation

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/write_xlsx/worksheet/data_validation.rb

Overview

:nodoc:

Constant Summary

Constants included from Utility

Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, #dash_types, delete_files, #fill_properties, #float_to_str, #layout_properties, #line_fill_properties, #line_properties, #palette_color, #pixels_to_points, #process_workbook_options, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_div, #write_fill, #write_font, #write_stroke, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Constructor Details

#initialize(*args) ⇒ DataValidation

Returns a new instance of DataValidation


13
14
15
16
17
18
19
20
21
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
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 13

def initialize(*args)
  # Check for a cell reference in A1 notation and substitute row and column.
  row1, col1, row2, col2, options = row_col_notation(args)
  if row2.respond_to?(:keys)
    options_to_instance_variable(row2.dup)
    row2, col2 = row1, col1
  elsif options.respond_to?(:keys)
    options_to_instance_variable(options.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]
  if @validate == 'none'
    @validate_none = true
    return
  end
  if ['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.
  if @input_title && @input_title.length > 32
    raise "Length of input title '#{@input_title}' exceeds Excel's limit of 32"
  end
  # Check that the input message doesn't exceed the maximum length.
  if @input_message && @input_message.length > 255
    raise "Length of input message '#{@input_message}' exceeds Excel's limit of 255"
  end
  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

#cellsObject (readonly)

Returns the value of attribute cells


9
10
11
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 9

def cells
  @cells
end

#criteriaObject (readonly)

Returns the value of attribute criteria


8
9
10
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 8

def criteria
  @criteria
end

Returns the value of attribute dropdown


10
11
12
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 10

def dropdown
  @dropdown
end

#error_messageObject (readonly)

Returns the value of attribute error_message


11
12
13
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 11

def error_message
  @error_message
end

#error_titleObject (readonly)

Returns the value of attribute error_title


11
12
13
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 11

def error_title
  @error_title
end

#error_typeObject (readonly)

Returns the value of attribute error_type


9
10
11
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 9

def error_type
  @error_type
end

#ignore_blankObject (readonly)

Returns the value of attribute ignore_blank


10
11
12
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 10

def ignore_blank
  @ignore_blank
end

#input_messageObject (readonly)

Returns the value of attribute input_message


11
12
13
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 11

def input_message
  @input_message
end

#input_titleObject (readonly)

Returns the value of attribute input_title


11
12
13
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 11

def input_title
  @input_title
end

#maximumObject (readonly)

Returns the value of attribute maximum


8
9
10
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 8

def maximum
  @maximum
end

#minimumObject (readonly)

Returns the value of attribute minimum


8
9
10
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 8

def minimum
  @minimum
end

#other_cellsObject (readonly)

Returns the value of attribute other_cells


9
10
11
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 9

def other_cells
  @other_cells
end

#show_errorObject (readonly)

Returns the value of attribute show_error


10
11
12
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 10

def show_error
  @show_error
end

#show_inputObject (readonly)

Returns the value of attribute show_input


10
11
12
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 10

def show_input
  @show_input
end

#sourceObject (readonly)

Returns the value of attribute source


8
9
10
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 8

def source
  @source
end

#validateObject (readonly)

Returns the value of attribute validate


8
9
10
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 8

def validate
  @validate
end

#valueObject (readonly)

Returns the value of attribute value


8
9
10
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 8

def value
  @value
end

Instance Method Details

#keysObject


72
73
74
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 72

def keys
  self.instance_variables.collect { |v| v.to_s.sub(/@/, '').to_sym }
end

#options_to_instance_variable(params) ⇒ Object


66
67
68
69
70
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 66

def options_to_instance_variable(params)
  params.each do |k, v|
    instance_variable_set("@#{k}", v)
  end
end

#validate_none?Boolean


76
77
78
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 76

def validate_none?
  @validate_none
end

#write_data_validation(writer) ⇒ Object

Write the <dataValidation> element.


83
84
85
86
87
88
89
90
91
# File 'lib/write_xlsx/worksheet/data_validation.rb', line 83

def write_data_validation(writer) #:nodoc:
  @writer = writer
  @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