Class: OOXL::Sheet::DataValidation

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/ooxl/xl_objects/sheet/data_validation.rb

Constant Summary

Constants included from Util

Util::COLUMN_LETTERS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#column_letter_to_number, #column_number_to_letter, #letter_equivalent, #letter_index, #node_attribute_value, #node_value_extractor, #to_column_letter, #uniform_reference

Instance Attribute Details

#allow_blankObject

Returns the value of attribute allow_blank.



5
6
7
# File 'lib/ooxl/xl_objects/sheet/data_validation.rb', line 5

def allow_blank
  @allow_blank
end

#formulaObject

Returns the value of attribute formula.



5
6
7
# File 'lib/ooxl/xl_objects/sheet/data_validation.rb', line 5

def formula
  @formula
end

#promptObject

Returns the value of attribute prompt.



5
6
7
# File 'lib/ooxl/xl_objects/sheet/data_validation.rb', line 5

def prompt
  @prompt
end

#sqrefObject

Returns the value of attribute sqref.



5
6
7
# File 'lib/ooxl/xl_objects/sheet/data_validation.rb', line 5

def sqref
  @sqref
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/ooxl/xl_objects/sheet/data_validation.rb', line 5

def type
  @type
end

Class Method Details

.load_from_node(data_validation_node) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ooxl/xl_objects/sheet/data_validation.rb', line 25

def self.load_from_node(data_validation_node)
  allow_blank = data_validation_node.attribute('allowBlank').try(:value)
  prompt = data_validation_node.attribute('prompt').try(:value)
  type = data_validation_node.attribute('type').try(:value)
  sqref = data_validation_node.attribute('sqref').try(:value) || data_validation_node.at('sqref').try(:content)
  formula = data_validation_node.at('formula1').try(:content)

  self.new(allow_blank: allow_blank,
           prompt: prompt,
           type: type,
           sqref: sqref,
           formula: formula)
end

Instance Method Details

#in_normalized_range?(range, letter_to_find) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/ooxl/xl_objects/sheet/data_validation.rb', line 17

def in_normalized_range?(range, letter_to_find)
  if range.first.length != range.last.length
    (column_letter_to_number(range.first)..column_letter_to_number(range.last)).include?(column_letter_to_number(letter_to_find))
  else
    range.include?(letter_to_find)
  end
end

#in_sqref_range?(cell_id) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
# File 'lib/ooxl/xl_objects/sheet/data_validation.rb', line 7

def in_sqref_range?(cell_id)
  return if cell_id.blank?
  cell_letter = cell_id.gsub(/[\d]/, '')
  index = cell_id.gsub(/[^\d]/, '').to_i
  range = sqref_range.find do |single_cell_letter_or_range, row_range|
    single_cell_letter_or_range.is_a?(Range) ? single_cell_letter_or_range.include?(cell_letter) || in_normalized_range?(single_cell_letter_or_range, cell_letter) : single_cell_letter_or_range == cell_letter
  end
  range.last.include?(index) if range.present?
end