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



33
34
35
# File 'lib/pincers/extension/queries.rb', line 33

def checked(_options={})
  first!.search('input', _options).select(&:checked?)
end

#classesObject



25
26
27
# File 'lib/pincers/extension/queries.rb', line 25

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

#downloadObject



48
49
50
51
52
# File 'lib/pincers/extension/queries.rb', line 48

def download
  url = attribute(:href) || attribute(:src)
  raise Pincers::NavigationError.new(self, 'No resource url was found') if url.nil?
  root.download(attribute(:href) || attribute(:src))
end

#idObject



6
7
8
# File 'lib/pincers/extension/queries.rb', line 6

def id
  self[:id]
end

#input_modeObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/pincers/extension/queries.rb', line 37

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



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

def selected(_options={})
  first!.search('option', _options).select(&:selected?)
end

#valueObject



10
11
12
13
14
15
16
17
# File 'lib/pincers/extension/queries.rb', line 10

def value
  case input_mode
  when :checkbox, :radio
    if checked? then self[:value] else nil end
  else
    self[:value]
  end
end