Module: Pincers::Extension::Queries
- Included in:
- Core::SearchContext
- Defined in:
- lib/pincers/extension/queries.rb
Constant Summary collapse
- TEXT_INPUTS =
['text', 'email', 'number', 'email', 'color', 'password', 'search', 'tel', 'url']
Instance Method Summary collapse
- #checked(_options = {}) ⇒ Object
- #classes ⇒ Object
- #input_mode ⇒ Object
- #selected(_options = {}) ⇒ Object
- #value ⇒ Object
Instance Method Details
#checked(_options = {}) ⇒ Object
29 30 31 |
# File 'lib/pincers/extension/queries.rb', line 29 def checked(={}) first!.css('input', ).select { |opt| opt.checked? } end |
#classes ⇒ Object
21 22 23 |
# File 'lib/pincers/extension/queries.rb', line 21 def classes (self[:class] || '').split(' ') end |
#input_mode ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pincers/extension/queries.rb', line 33 def input_mode return :select if tag == 'select' return :button if tag == 'button' # TODO: button types return :text if tag == 'textarea' return nil if tag != 'input' type = (self[:type] || 'text').downcase return :text if TEXT_INPUTS.include? type type.to_sym end |
#selected(_options = {}) ⇒ Object
25 26 27 |
# File 'lib/pincers/extension/queries.rb', line 25 def selected(={}) first!.css('option', ).select { |opt| opt.selected? } end |
#value ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/pincers/extension/queries.rb', line 6 def value case input_mode when :checkbox, :radio if checked? then self[:value] else nil end else self[:value] end end |