quote 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/quote +12 -4
  2. data/lib/quote.rb +6 -0
  3. 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
- puts USAGE; exit(0) if flag == '--help'
29
- puts Quote.add(arg); exit(0) if flag == '--add'
30
- criteria[flag.gsub('--','')] = arg
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
- puts Quote.say(criteria)
46
+
47
+ puts say_all ? Quote.say_all(criteria) : Quote.say(criteria)
@@ -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
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quote
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 7
10
- version: 0.1.7
9
+ - 8
10
+ version: 0.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - tjbladez