Class: Omnibar::Query

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

Direct Known Subclasses

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

Defined Under Namespace

Modules: MethodAugmentations

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
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
13
# File 'lib/omnibar/query.rb', line 9

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

Instance Method Details

#copy_to_clipboard(value) ⇒ Object



40
41
42
# File 'lib/omnibar/query.rb', line 40

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

#labelObject



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

def label
  self.class.name.split('::').last.gsub(/[A-Z]/) { |w| ' ' << w }.strip
end

#open_in_browser(url) ⇒ Object



44
45
46
# File 'lib/omnibar/query.rb', line 44

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

#perform!Object



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

def perform!; end

#preview_textObject

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



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

def preview_text
  res = result
  [label, res.strip] unless res.nil? || res.empty?
end

#relevanceObject



34
35
36
# File 'lib/omnibar/query.rb', line 34

def relevance
  0
end

#resultObject



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

def result
  input
end

#run_silently(*command) ⇒ Object



48
49
50
# File 'lib/omnibar/query.rb', line 48

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

#searchObject



30
31
32
# File 'lib/omnibar/query.rb', line 30

def search
  self.class.search
end