Module: CapybaraSelect2::Utils
- Defined in:
- lib/capybara_select2/utils.rb
Class Method Summary collapse
- .detect_select2_version(container) ⇒ Object
- .find_select2_container(options, page) ⇒ Object
- .validate_options!(options) ⇒ Object
Class Method Details
.detect_select2_version(container) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/capybara_select2/utils.rb', line 4 def self.detect_select2_version(container) if container['class'] =~ /^select2\s/ '4' elsif container['id'] =~ /^s2id_/ '3' else '2' end end |
.find_select2_container(options, page) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/capybara_select2/utils.rb', line 20 def self.find_select2_container(, page) container = if [:xpath] page.find(:xpath, [:xpath]) elsif [:css] page.find(:css, [:css]) else page.find(:css, "label:not(.select2-offscreen)", text: [:from]) .find(:xpath, '..') .find(:css, '.select2-container') end if container['class'] =~ /select2-container/ container else container.find(:css, '.select2-container') end end |
.validate_options!(options) ⇒ Object
14 15 16 17 18 |
# File 'lib/capybara_select2/utils.rb', line 14 def self.() unless .is_a?(Hash) && [:css, :xpath, :from].any? { |k| .key?(k) } fail ArgumentError.new("Please specify :css, :xpath or :from in options") end end |