quote 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/quote +12 -4
- data/lib/quote.rb +6 -0
- metadata +3 -3
data/bin/quote
CHANGED
@@ -11,6 +11,7 @@ Or you may use following options:
|
|
11
11
|
#{'quote --context/-c <argument>'.green} to search for a match in context quote was originated (ex. 'pulp fiction')
|
12
12
|
#{'quote --source/-s <argument>'.green} to search for a match in originator of the quote (ex. 'the dude')
|
13
13
|
#{'quote --add/-a <argument>'.green} to add a quote your argument needs to be a valid JSON containing source, context, quote, theme params
|
14
|
+
#{'quote --all/-e'.green} to search for all quotes with matches
|
14
15
|
#{'quote --help/-h'.green} to see this message
|
15
16
|
You can see pretty colorized output if you set environment variable QUOTE_COLORIZE to 'true'.
|
16
17
|
You can specify your own path to quotes files via environment variable QUOTE_SOURCE.
|
@@ -18,16 +19,22 @@ Search by multiple criteria is supported.
|
|
18
19
|
EOU
|
19
20
|
|
20
21
|
opts = GetoptLong.new(['--help', '-h', GetoptLong::NO_ARGUMENT],
|
22
|
+
['--all', '-e', GetoptLong::NO_ARGUMENT],
|
23
|
+
['--add','-a', GetoptLong::REQUIRED_ARGUMENT],
|
21
24
|
['--source','-s', GetoptLong::REQUIRED_ARGUMENT],
|
22
25
|
['--context','-c', GetoptLong::REQUIRED_ARGUMENT],
|
23
26
|
['--quote','-q', GetoptLong::REQUIRED_ARGUMENT],
|
24
27
|
['--theme','-t', GetoptLong::REQUIRED_ARGUMENT])
|
25
28
|
criteria = {}
|
29
|
+
say_all = false
|
26
30
|
begin
|
27
31
|
opts.each do |flag, arg|
|
28
|
-
|
29
|
-
puts
|
30
|
-
|
32
|
+
case(flag)
|
33
|
+
when '--help' then puts USAGE; exit(0)
|
34
|
+
when '--add' then puts Quote.add(arg); exit(0)
|
35
|
+
when '--all' then say_all = true
|
36
|
+
else criteria[flag.gsub('--', '')] = arg
|
37
|
+
end
|
31
38
|
end
|
32
39
|
rescue GetoptLong::InvalidOption => e
|
33
40
|
puts "Please type quote -h for usage"
|
@@ -36,4 +43,5 @@ rescue GetoptLong::MissingArgument => e
|
|
36
43
|
puts "You do need to pass an argument for matching"
|
37
44
|
exit(0)
|
38
45
|
end
|
39
|
-
|
46
|
+
|
47
|
+
puts say_all ? Quote.say_all(criteria) : Quote.say(criteria)
|
data/lib/quote.rb
CHANGED
@@ -45,6 +45,12 @@ module Quote
|
|
45
45
|
ENV['QUOTE_COLORIZE'] == "true" ? random_quote.format_with_color : random_quote.format
|
46
46
|
end
|
47
47
|
|
48
|
+
def say_all(criteria = {})
|
49
|
+
quotes = load_quotes.where(criteria)
|
50
|
+
return "No quotes found" if quotes.empty?
|
51
|
+
ENV['QUOTE_COLORIZE'] == "true" ? quotes.map(&:format_with_color) : quotes.map(&:format)
|
52
|
+
end
|
53
|
+
|
48
54
|
def add(json)
|
49
55
|
quote = Yajl::Parser.parse(json)
|
50
56
|
missing_criteria = []
|
metadata
CHANGED