delicious-cli 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -104,9 +104,13 @@ class Database
104
104
  @@posts << params
105
105
  end
106
106
 
107
- def self.find(query)
108
- query = "%#{query}%" if query.is_a? String
109
- @@posts.filter(:extended.like(query) | :description.like(query) | :tag.like(query)).order(:time)
107
+ def self.find(words)
108
+ sequel_query = @@posts
109
+ for word in words
110
+ pattern = "%#{word}%"
111
+ sequel_query = sequel_query.filter(:extended.like(pattern) | :description.like(pattern) | :tag.like(pattern))
112
+ end
113
+ sequel_query.order(:time)
110
114
  end
111
115
 
112
116
 
@@ -8,16 +8,25 @@ begin
8
8
  require 'colorize'
9
9
  # Colourized hilite...
10
10
  class String
11
- def hilite(query, color=:white)
12
- query = Regexp.new( Regexp.escape(query), Regexp::IGNORECASE )
13
- self.to_s.send(color).gsub(/(.*)(#{query})(.*)/) { $1.send(color) + $2.black.on_yellow + $3.send(color)}
11
+ def hilite(words, color=:white)
12
+ escaped_words = words.map { |word| Regexp.escape(word) }
13
+ matcher = /(#{escaped_words.join('|')})/io
14
+
15
+ chunks = self.to_s.split(matcher)
16
+ chunks.map do |chunk|
17
+ if chunk =~ matcher
18
+ chunk.black.on_yellow
19
+ else
20
+ chunk.send(color)
21
+ end
22
+ end.join('')
14
23
  end
15
24
  end
16
25
  rescue LoadError
17
26
  STDERR.puts "Note: You should install the 'colorize' gem for extra prettiness.\n"
18
27
  # Monochrome hilite does nothing...
19
28
  class String
20
- def hilite(query); self; end
29
+ def hilite(words); self; end
21
30
  end
22
31
  end
23
32
 
data/lib/delicious-cli.rb CHANGED
@@ -24,9 +24,9 @@ end
24
24
 
25
25
  #################################################################
26
26
 
27
- def search(query)
28
- matches = Database.find(query)
29
- matches.each { |match| display(match, query) }
27
+ def search(words)
28
+ matches = Database.find(words)
29
+ matches.each { |match| display(match, words) }
30
30
  end
31
31
 
32
32
  def sync
@@ -148,9 +148,8 @@ def main
148
148
  elsif options.sync
149
149
  sync
150
150
  else
151
- exit 1 unless query = ARGV[0]
152
- query = ARGV[0]
153
- search(query)
151
+ exit 1 unless ARGV.size > 0
152
+ search(ARGV)
154
153
  end
155
154
 
156
155
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delicious-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron