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

Instance Method Details

#checked(_options = {}) ⇒ Object



29
30
31
# File 'lib/pincers/extension/queries.rb', line 29

def checked(_options={})
  first!.css('input', _options).select { |opt| opt.checked? }
end

#classesObject



21
22
23
# File 'lib/pincers/extension/queries.rb', line 21

def classes
  (self[:class] || '').split(' ')
end

#input_modeObject



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(_options={})
  first!.css('option', _options).select { |opt| opt.selected? }
end

#valueObject



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