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.
- data/lib/delicious-cli/db.rb +7 -3
- data/lib/delicious-cli/display.rb +13 -4
- data/lib/delicious-cli.rb +5 -6
- metadata +1 -1
data/lib/delicious-cli/db.rb
CHANGED
@@ -104,9 +104,13 @@ class Database
|
|
104
104
|
@@posts << params
|
105
105
|
end
|
106
106
|
|
107
|
-
def self.find(
|
108
|
-
|
109
|
-
|
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(
|
12
|
-
|
13
|
-
|
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(
|
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(
|
28
|
-
matches = Database.find(
|
29
|
-
matches.each { |match| display(match,
|
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
|
152
|
-
|
153
|
-
search(query)
|
151
|
+
exit 1 unless ARGV.size > 0
|
152
|
+
search(ARGV)
|
154
153
|
end
|
155
154
|
|
156
155
|
end
|