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
- #download ⇒ Object
- #id ⇒ Object
- #input_mode ⇒ Object
- #selected(_options = {}) ⇒ Object
- #value ⇒ Object
Instance Method Details
#checked(_options = {}) ⇒ Object
33 34 35 |
# File 'lib/pincers/extension/queries.rb', line 33 def checked(={}) first!.search('input', ).select(&:checked?) end |
#classes ⇒ Object
25 26 27 |
# File 'lib/pincers/extension/queries.rb', line 25 def classes (self[:class] || '').split(' ') end |
#download ⇒ Object
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 |
#id ⇒ Object
6 7 8 |
# File 'lib/pincers/extension/queries.rb', line 6 def id self[:id] end |
#input_mode ⇒ Object
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(={}) first!.search('option', ).select(&:selected?) end |
#value ⇒ Object
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 |