Class: Omnibar::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/omnibar/query.rb

Direct Known Subclasses

Calculate, DuckDuckGo, Emoji, Github, Google, Popular, Snippet, Spell, System

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Query

Returns a new instance of Query.



5
6
7
# File 'lib/omnibar/query.rb', line 5

def initialize(input)
  @input = input.strip
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



3
4
5
# File 'lib/omnibar/query.rb', line 3

def input
  @input
end

Class Method Details

.inherited(subclass) ⇒ Object



9
10
11
12
# File 'lib/omnibar/query.rb', line 9

def self.inherited(subclass)
  Omnibar.config.queries.push(subclass)
  super(subclass)
end

Instance Method Details

#copy_to_clipboard(value) ⇒ Object



28
29
30
# File 'lib/omnibar/query.rb', line 28

def copy_to_clipboard(value)
  `echo "#{value}" | xsel -i --clipboard`
end

#open_in_browser(url) ⇒ Object



32
33
34
# File 'lib/omnibar/query.rb', line 32

def open_in_browser(url)
  Thread.new { run_silently 'xdg-open', url }
end

#perform!Object



26
# File 'lib/omnibar/query.rb', line 26

def perform!; end

#preview_textObject

TODO: Convert result to class TODO: Allow multiple results per query



16
17
18
19
20
# File 'lib/omnibar/query.rb', line 16

def preview_text
  res = result
  name = self.class.name.split('::').last.gsub(/[A-Z]/) { |w| ' ' << w }.strip
  [name, res.strip] unless res.nil? || res.empty?
end

#resultObject



22
23
24
# File 'lib/omnibar/query.rb', line 22

def result
  input
end

#run_silently(*command) ⇒ Object



36
37
38
# File 'lib/omnibar/query.rb', line 36

def run_silently(*command)
  `#{command.join(' ')} >/dev/null 2>&1`
end