lyracyst 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52dc9e24fd2289f6afd97edaa876f8b0c3cc418a
4
- data.tar.gz: 00e086cdbf93d6763e57f88e695e6861428681f7
3
+ metadata.gz: eb07368fe2368b27ee37ec8f70d7f2d2a148db91
4
+ data.tar.gz: 22429d86922fcb5e73fe5a98981923da40e8d46b
5
5
  SHA512:
6
- metadata.gz: c2b5e8a37901f2f74819ae12eb5273e6b462cbe2db7f8da8b5bcaaf5a7c200c9fd9ce20eb486392f348c8576c009797bb7cfd37fa9ff9de1dd69aa1c435793b4
7
- data.tar.gz: 8f18730e1c9ba61d752cd4474cf5a25ce7ae752b79f33f27ffd2c95f98cc5cd6618b32c26857d5830752b38971c4baac728fbc621cbd8ea731cda60d98dbe52b
6
+ metadata.gz: 500198b5c4ee3a14352f07b62f0efd98f01dc62506fc2e93d9e851278537824a3b16c389afbe3e94d4b3f0999c399615255753755c541d25ff424d6d57ea10ec
7
+ data.tar.gz: 00aa7522afc18725af26ae6076fe31d4376bb18877e07db6baccaac69e2adced4757103dc675923688b10b11998a6ddc6745c27bb2f68967969380ed5f15a750
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  Changelog
2
2
  ===
3
3
 
4
+ Version 0.0.8 - Major Improvements
5
+ - The biggest milestone yet!
6
+ - Most Wordnik search functions now work
7
+ - Removed Altervista related words in favor of using Wordnik
8
+ - Migrated from [ARPABET](http://arpabet.heroku.com) to [Rhymebrain](http://rhymebrain.com/api.html) and using it to fetch rhymes, word info, and portmanteaus
9
+ - Migrated from [commander](http://github.com/visionmedia/commander) to [gli](http://github.com/davetron5000/gli) for CLI interface
10
+ - Configuration file for defaults (~/.lyracyst.yml)
11
+
4
12
  Version 0.0.7 - Tests, Optimization, & More Cleanup
5
13
  - Better docs
6
14
  - Testing on more Ruby implementations
data/bin/lyracyst CHANGED
@@ -1,27 +1,80 @@
1
1
  #!/usr/bin/env ruby
2
2
  # coding: utf-8
3
+ #%w(curb em-synchrony em-http eventmachine excon httpclient httpi net/http/persistent rainbow).map {|lib| require lib}
4
+ #%w(json/ext json/pure multi_json oj yajl).map {|lib| require lib}
5
+ #%w(libxml multi_xml ox rexml/document).map {|lib| require lib}
3
6
  require 'gli'
4
- require './lib/lyracyst/rhymebrain.rb'
5
- require './lib/lyracyst/version.rb'
6
- require './lib/lyracyst/wordnik.rb'
7
+ require 'lyracyst/rhymebrain'
8
+ require 'lyracyst/urban'
9
+ require 'lyracyst/version'
10
+ require 'lyracyst/wordnik'
11
+ require 'xml-fu'
12
+ module Lyracyst
13
+
14
+ HTTPI.log = false
15
+
16
+ # Optionally sets HTTP adapter with httpi. Supports [:httpclient,
17
+ # :curb, :em_http, :net_http_persistent, :excon, :rack]
18
+ #
19
+ # @param http [Symbol] The http adapter to use. Smart defaults.
20
+ def self.set_http(http)
21
+ HTTPI.adapter = http
22
+ end
23
+
24
+ # Optionally sets JSON adapter with multi_json. Supports [:oj,
25
+ # :yajl, :json_gem, :json_pure]
26
+ #
27
+ # @param mj [Symbol] The JSON adapter to use. Smart defaults.
28
+ def self.set_json(mj)
29
+ MultiJson.use(mj)
30
+ end
31
+
32
+ # Optionally sets XML adapter with multi_xml. Supports [:ox,
33
+ # :libxml, :nokogiri, :rexml]
34
+ #
35
+ # @param mx [Symbol] The XML adapter to use. Smart defaults.
36
+ def self.set_xml(mx)
37
+ MultiXml.parser = mx
38
+ end
39
+
40
+ # Prints colored element label.
41
+ #
42
+ # @param label [String] The label to print
43
+ def self.label(label)
44
+ print Rainbow('[').blue.bright
45
+ print Rainbow(label).green.bright
46
+ print Rainbow(']').blue.bright
47
+ print Rainbow('|').bright
48
+ end
49
+ end
7
50
 
8
51
  include GLI::App
9
- program_desc 'A powerful word search tool that fetches definitions, related words, rhymes, and much more.'
52
+ program_desc 'A powerful word search tool that fetches definitions, related words, rhymes, and much more. Rhymes are provided by rhymebrain.com.'
10
53
  config_file '.lyracyst.yml'
11
54
  version Lyracyst::VERSION
12
55
 
56
+ desc 'Force overwrite'
57
+ long_desc 'Overwrites existing JSON & XML files'
58
+ switch [:f,:force]
59
+
13
60
  desc 'HTTP adapter'
14
61
  long_desc 'httpclient, curb, em_http, net_http_persistent, excon, rack'
15
- default_value :excon
62
+ default_value :net_http_persistent
16
63
  arg_name 'http'
17
64
  flag [:h,:http]
18
65
 
19
66
  desc 'JSON adapter'
20
67
  long_desc 'oj, yajl, json_gem, json_pure'
21
- default_value :json_pure
68
+ default_value :oj
22
69
  arg_name 'json'
23
70
  flag [:j,:json]
24
71
 
72
+ desc 'Output file'
73
+ long_desc 'filename.json or filename.xml'
74
+ default_value nil
75
+ arg_name 'outfile'
76
+ flag [:o,:out]
77
+
25
78
  desc 'XML adapter'
26
79
  long_desc 'ox, libxml, nokogiri, rexml'
27
80
  default_value :rexml
@@ -46,7 +99,7 @@ command :define do |c|
46
99
  part = options[:p]
47
100
  params = {limit: 10, increl: false, canon: false, inctags: false}
48
101
  params[:defdict] = options[:defdict]
49
- df = Lyracyst::Wordnik.new
102
+ df = Lyracyst::Wordnik::Define.new
50
103
  df.get_def(search, part, params)
51
104
  end
52
105
  end
@@ -69,7 +122,7 @@ command :example do |c|
69
122
  params = {incdups: false, canon: false}
70
123
  params[:skip] = skip
71
124
  params[:limit] = limit
72
- ex = Lyracyst::Wordnik.new
125
+ ex = Lyracyst::Wordnik::Example.new
73
126
  ex.get_ex(search, params)
74
127
  end
75
128
  end
@@ -91,7 +144,7 @@ command :relate do |c|
91
144
  rellimit = options[:rell]
92
145
  params = {canon: false}
93
146
  params[:rellimit] = rellimit
94
- ex = Lyracyst::Wordnik.new
147
+ ex = Lyracyst::Wordnik::Relate.new
95
148
  ex.get_rel(search, params, reltypes)
96
149
  end
97
150
  end
@@ -120,7 +173,7 @@ command :pronounce do |c|
120
173
  params = {canon: false}
121
174
  params[:source] = source
122
175
  params[:limit] = limit
123
- pr = Lyracyst::Wordnik.new
176
+ pr = Lyracyst::Wordnik::Pronounce.new
124
177
  pr.get_pro(search, params, ptype)
125
178
  end
126
179
  end
@@ -143,7 +196,7 @@ command :hyphen do |c|
143
196
  params = {canon: false}
144
197
  if source != nil then params[:source] = source; end
145
198
  params[:limit] = limit
146
- hyph = Lyracyst::Wordnik.new
199
+ hyph = Lyracyst::Wordnik::Hyphen.new
147
200
  hyph.get_hyph(search, params)
148
201
  end
149
202
  end
@@ -166,7 +219,7 @@ command :phrase do |c|
166
219
  params = {canon: false}
167
220
  params[:limit] = limit
168
221
  params[:wlmi] = wlmi
169
- phra = Lyracyst::Wordnik.new
222
+ phra = Lyracyst::Wordnik::Phrase.new
170
223
  phra.get_phr(search, params)
171
224
  end
172
225
  end
@@ -177,12 +230,12 @@ command :origin do |c|
177
230
  c.action do |global_options,options,args|
178
231
  search = args[0]
179
232
  params = {canon: false}
180
- orig = Lyracyst::Wordnik.new
233
+ orig = Lyracyst::Wordnik::Origin.new
181
234
  orig.get_et(search, params)
182
235
  end
183
236
  end
184
237
 
185
- desc 'Fetches rhymes from Rhymebrain'
238
+ desc 'Fetches rhymes from Rhymebrain.com'
186
239
  arg_name 'word'
187
240
  command :rhyme do |c|
188
241
  c.desc 'ISO639-1 language code (optional). Eg. en, de, es, fr, ru'
@@ -200,12 +253,12 @@ command :rhyme do |c|
200
253
  params = {}
201
254
  params[:lang] = lang
202
255
  params[:max] = max
203
- rhym = Lyracyst::Rhymebrain.new
256
+ rhym = Lyracyst::Rhymebrain::Rhyme.new
204
257
  rhym.get_rhyme(search, params)
205
258
  end
206
259
  end
207
260
 
208
- desc 'Fetches word info from Rhymebrain'
261
+ desc 'Fetches word info from Rhymebrain.com'
209
262
  arg_name 'word'
210
263
  command :info do |c|
211
264
  c.desc 'ISO639-1 language code (optional). Eg. en, de, es, fr, ru'
@@ -223,12 +276,12 @@ command :info do |c|
223
276
  params = {}
224
277
  params[:lang] = lang
225
278
  params[:max] = max
226
- info = Lyracyst::Rhymebrain.new
279
+ info = Lyracyst::Rhymebrain::Info.new
227
280
  info.get_info(search, params)
228
281
  end
229
282
  end
230
283
 
231
- desc 'Fetches combined words (portmanteaus) from Rhymebrain'
284
+ desc 'Fetches combined words (portmanteaus) from Rhymebrain.com'
232
285
  arg_name 'word'
233
286
  command :combine do |c|
234
287
  c.desc 'ISO639-1 language code (optional). Eg. en, de, es, fr, ru'
@@ -246,41 +299,61 @@ arg_name 'word'
246
299
  params = {}
247
300
  params[:lang] = lang
248
301
  params[:max] = max
249
- port = Lyracyst::Rhymebrain.new
302
+ port = Lyracyst::Rhymebrain::Combine.new
250
303
  port.get_port(search, params)
251
304
  end
252
305
  end
253
306
 
307
+ desc 'Fetches definitions from Urban Dictionary'
308
+ arg_name 'word'
309
+ command :urban do |c|
310
+ c.action do |global_options,options,args|
311
+ search = args[0]
312
+ ur = Lyracyst::Urban::Define.new
313
+ ur.get_def(search)
314
+ end
315
+ end
316
+
254
317
  pre do |global,command,options,args|
255
318
  # Pre logic here
256
319
  # Return true to proceed; false to abort and not call the
257
320
  # chosen command
258
321
  # Use skips_pre before a command to skip this block
259
322
  # on that command only
260
- wn = Lyracyst::Wordnik.new
323
+ if global[:o] != nil
324
+ outfile = global[:o]
325
+ if outfile =~ /\w*\.json/
326
+ $fmt = :json
327
+ elsif outfile =~ /\w*.xml/
328
+ $fmt = :xml
329
+ else
330
+ puts 'Invalid file extension.'
331
+ end
332
+ $tofile = []
333
+ end
261
334
  http = global[:h]
262
335
  json = global[:j]
263
336
  xml = global[:x]
264
337
  if http.class != Symbol then http = http.to_sym; end
265
- wn.set_http(http)
338
+ Lyracyst.set_http(http)
266
339
  if json.class != Symbol then json = json.to_sym; end
267
- wn.set_json(json)
340
+ Lyracyst.set_json(json)
268
341
  if xml.class != Symbol then xml = xml.to_sym; end
269
- wn.set_xml(xml)
342
+ Lyracyst.set_xml(xml)
270
343
  label = 'Global options'
271
- wn.label(label)
272
- print "- #{global} "
344
+ Lyracyst.label(label)
345
+ print "➜#{global}"
273
346
  label = 'Command'
274
- wn.label(label)
275
- print "- #{command.name} "
347
+ Lyracyst.label(label)
348
+ print "➜#{command.name}"
276
349
  label = 'Command options'
277
- wn.label(label)
278
- print "- #{options} "
350
+ Lyracyst.label(label)
351
+ print "➜#{options}"
279
352
  label = 'Args'
280
- wn.label(label)
281
- print "- #{args} "
353
+ Lyracyst.label(label)
354
+ print "➜#{args}"
282
355
  label = 'Bootstrapped'
283
- wn.label(label)
356
+ Lyracyst.label(label)
284
357
  puts ''
285
358
  true
286
359
  end
@@ -289,9 +362,61 @@ post do |global,command,options,args|
289
362
  # Post logic here
290
363
  # Use skips_post before a command to skip this
291
364
  # block on that command only
292
- wn = Lyracyst::Wordnik.new
293
- label = 'Shutdown'
294
- wn.label(label)
365
+ if $fmt != nil
366
+ outfile = global[:o]
367
+ if File.exist?(outfile) && global[:f] == true
368
+ if $fmt == :json
369
+ fo = File.open(outfile, 'w+')
370
+ fo.print MultiJson.dump($tofile)
371
+ fo.close
372
+ elsif $fmt == :xml
373
+ fo = File.open(outfile, 'w+')
374
+ fo.print '<?xml version="1.0" encoding="utf-8"?>'
375
+ fo.print XmlFu.xml($tofile)
376
+ fo.close
377
+ else
378
+ puts 'Invalid file extension.'
379
+ end
380
+ puts Rainbow("Word search was written to #{outfile}.").bright
381
+ end
382
+ if File.exist?(outfile) && global[:f] == false
383
+ puts Rainbow("#{outfile} exists. Overwrite? y/n ").bright
384
+ ans = gets
385
+ if ans =~ /y/
386
+ if $fmt == :json
387
+ fo = File.open(outfile, 'w+')
388
+ fo.print MultiJson.dump($tofile)
389
+ fo.close
390
+ elsif $fmt == :xml
391
+ fo = File.open(outfile, 'w+')
392
+ fo.print '<?xml version="1.0" encoding="utf-8"?>'
393
+ fo.print XmlFu.xml($tofile)
394
+ fo.close
395
+ else
396
+ puts 'Invalid file extension.'
397
+ end
398
+ puts Rainbow("Word search was written to #{outfile}.").bright
399
+ else
400
+ puts 'Please try again with a different filename.'
401
+ end
402
+ else
403
+ if $fmt == :json
404
+ fo = File.open(outfile, 'w+')
405
+ fo.print MultiJson.dump($tofile)
406
+ fo.close
407
+ elsif $fmt == :xml
408
+ fo = File.open(outfile, 'w+')
409
+ fo.print '<?xml version="1.0" encoding="utf-8"?>'
410
+ fo.print XmlFu.xml($tofile)
411
+ fo.close
412
+ else
413
+ puts 'Invalid file extension.'
414
+ end
415
+ puts Rainbow("Word search was written to #{outfile}.").bright
416
+ end
417
+ end
418
+ label = 'Shutdown'
419
+ Lyracyst.label(label)
295
420
  puts ''
296
421
  end
297
422
 
@@ -300,5 +425,4 @@ on_error do |exception|
300
425
  # return false to skip default error handling
301
426
  true
302
427
  end
303
-
304
428
  exit run(ARGV)
data/lib/lyracyst.rb CHANGED
@@ -1,27 +1,80 @@
1
1
  #!/usr/bin/env ruby
2
2
  # coding: utf-8
3
+ #%w(curb em-synchrony em-http eventmachine excon httpclient httpi net/http/persistent rainbow).map {|lib| require lib}
4
+ #%w(json/ext json/pure multi_json oj yajl).map {|lib| require lib}
5
+ #%w(libxml multi_xml ox rexml/document).map {|lib| require lib}
3
6
  require 'gli'
4
7
  require 'lyracyst/rhymebrain'
8
+ require 'lyracyst/urban'
5
9
  require 'lyracyst/version'
6
10
  require 'lyracyst/wordnik'
11
+ require 'xml-fu'
12
+ module Lyracyst
13
+
14
+ HTTPI.log = false
15
+
16
+ # Optionally sets HTTP adapter with httpi. Supports [:httpclient,
17
+ # :curb, :em_http, :net_http_persistent, :excon, :rack]
18
+ #
19
+ # @param http [Symbol] The http adapter to use. Smart defaults.
20
+ def self.set_http(http)
21
+ HTTPI.adapter = http
22
+ end
23
+
24
+ # Optionally sets JSON adapter with multi_json. Supports [:oj,
25
+ # :yajl, :json_gem, :json_pure]
26
+ #
27
+ # @param mj [Symbol] The JSON adapter to use. Smart defaults.
28
+ def self.set_json(mj)
29
+ MultiJson.use(mj)
30
+ end
31
+
32
+ # Optionally sets XML adapter with multi_xml. Supports [:ox,
33
+ # :libxml, :nokogiri, :rexml]
34
+ #
35
+ # @param mx [Symbol] The XML adapter to use. Smart defaults.
36
+ def self.set_xml(mx)
37
+ MultiXml.parser = mx
38
+ end
39
+
40
+ # Prints colored element label.
41
+ #
42
+ # @param label [String] The label to print
43
+ def self.label(label)
44
+ print Rainbow('[').blue.bright
45
+ print Rainbow(label).green.bright
46
+ print Rainbow(']').blue.bright
47
+ print Rainbow('|').bright
48
+ end
49
+ end
7
50
 
8
51
  include GLI::App
9
- program_desc 'A powerful word search tool that fetches definitions, related words, rhymes, and much more.'
52
+ program_desc 'A powerful word search tool that fetches definitions, related words, rhymes, and much more. Rhymes are provided by rhymebrain.com.'
10
53
  config_file '.lyracyst.yml'
11
54
  version Lyracyst::VERSION
12
55
 
56
+ desc 'Force overwrite'
57
+ long_desc 'Overwrites existing JSON & XML files'
58
+ switch [:f,:force]
59
+
13
60
  desc 'HTTP adapter'
14
61
  long_desc 'httpclient, curb, em_http, net_http_persistent, excon, rack'
15
- default_value :excon
62
+ default_value :net_http_persistent
16
63
  arg_name 'http'
17
64
  flag [:h,:http]
18
65
 
19
66
  desc 'JSON adapter'
20
67
  long_desc 'oj, yajl, json_gem, json_pure'
21
- default_value :json_pure
68
+ default_value :oj
22
69
  arg_name 'json'
23
70
  flag [:j,:json]
24
71
 
72
+ desc 'Output file'
73
+ long_desc 'filename.json or filename.xml'
74
+ default_value nil
75
+ arg_name 'outfile'
76
+ flag [:o,:out]
77
+
25
78
  desc 'XML adapter'
26
79
  long_desc 'ox, libxml, nokogiri, rexml'
27
80
  default_value :rexml
@@ -46,7 +99,7 @@ command :define do |c|
46
99
  part = options[:p]
47
100
  params = {limit: 10, increl: false, canon: false, inctags: false}
48
101
  params[:defdict] = options[:defdict]
49
- df = Lyracyst::Wordnik.new
102
+ df = Lyracyst::Wordnik::Define.new
50
103
  df.get_def(search, part, params)
51
104
  end
52
105
  end
@@ -69,7 +122,7 @@ command :example do |c|
69
122
  params = {incdups: false, canon: false}
70
123
  params[:skip] = skip
71
124
  params[:limit] = limit
72
- ex = Lyracyst::Wordnik.new
125
+ ex = Lyracyst::Wordnik::Example.new
73
126
  ex.get_ex(search, params)
74
127
  end
75
128
  end
@@ -91,7 +144,7 @@ command :relate do |c|
91
144
  rellimit = options[:rell]
92
145
  params = {canon: false}
93
146
  params[:rellimit] = rellimit
94
- ex = Lyracyst::Wordnik.new
147
+ ex = Lyracyst::Wordnik::Relate.new
95
148
  ex.get_rel(search, params, reltypes)
96
149
  end
97
150
  end
@@ -120,7 +173,7 @@ command :pronounce do |c|
120
173
  params = {canon: false}
121
174
  params[:source] = source
122
175
  params[:limit] = limit
123
- pr = Lyracyst::Wordnik.new
176
+ pr = Lyracyst::Wordnik::Pronounce.new
124
177
  pr.get_pro(search, params, ptype)
125
178
  end
126
179
  end
@@ -143,7 +196,7 @@ command :hyphen do |c|
143
196
  params = {canon: false}
144
197
  if source != nil then params[:source] = source; end
145
198
  params[:limit] = limit
146
- hyph = Lyracyst::Wordnik.new
199
+ hyph = Lyracyst::Wordnik::Hyphen.new
147
200
  hyph.get_hyph(search, params)
148
201
  end
149
202
  end
@@ -166,7 +219,7 @@ command :phrase do |c|
166
219
  params = {canon: false}
167
220
  params[:limit] = limit
168
221
  params[:wlmi] = wlmi
169
- phra = Lyracyst::Wordnik.new
222
+ phra = Lyracyst::Wordnik::Phrase.new
170
223
  phra.get_phr(search, params)
171
224
  end
172
225
  end
@@ -177,12 +230,12 @@ command :origin do |c|
177
230
  c.action do |global_options,options,args|
178
231
  search = args[0]
179
232
  params = {canon: false}
180
- orig = Lyracyst::Wordnik.new
233
+ orig = Lyracyst::Wordnik::Origin.new
181
234
  orig.get_et(search, params)
182
235
  end
183
236
  end
184
237
 
185
- desc 'Fetches rhymes from Rhymebrain'
238
+ desc 'Fetches rhymes from Rhymebrain.com'
186
239
  arg_name 'word'
187
240
  command :rhyme do |c|
188
241
  c.desc 'ISO639-1 language code (optional). Eg. en, de, es, fr, ru'
@@ -200,12 +253,12 @@ command :rhyme do |c|
200
253
  params = {}
201
254
  params[:lang] = lang
202
255
  params[:max] = max
203
- rhym = Lyracyst::Rhymebrain.new
256
+ rhym = Lyracyst::Rhymebrain::Rhyme.new
204
257
  rhym.get_rhyme(search, params)
205
258
  end
206
259
  end
207
260
 
208
- desc 'Fetches word info from Rhymebrain'
261
+ desc 'Fetches word info from Rhymebrain.com'
209
262
  arg_name 'word'
210
263
  command :info do |c|
211
264
  c.desc 'ISO639-1 language code (optional). Eg. en, de, es, fr, ru'
@@ -223,12 +276,12 @@ command :info do |c|
223
276
  params = {}
224
277
  params[:lang] = lang
225
278
  params[:max] = max
226
- info = Lyracyst::Rhymebrain.new
279
+ info = Lyracyst::Rhymebrain::Info.new
227
280
  info.get_info(search, params)
228
281
  end
229
282
  end
230
283
 
231
- desc 'Fetches combined words (portmanteaus) from Rhymebrain'
284
+ desc 'Fetches combined words (portmanteaus) from Rhymebrain.com'
232
285
  arg_name 'word'
233
286
  command :combine do |c|
234
287
  c.desc 'ISO639-1 language code (optional). Eg. en, de, es, fr, ru'
@@ -246,41 +299,61 @@ arg_name 'word'
246
299
  params = {}
247
300
  params[:lang] = lang
248
301
  params[:max] = max
249
- port = Lyracyst::Rhymebrain.new
302
+ port = Lyracyst::Rhymebrain::Combine.new
250
303
  port.get_port(search, params)
251
304
  end
252
305
  end
253
306
 
307
+ desc 'Fetches definitions from Urban Dictionary'
308
+ arg_name 'word'
309
+ command :urban do |c|
310
+ c.action do |global_options,options,args|
311
+ search = args[0]
312
+ ur = Lyracyst::Urban::Define.new
313
+ ur.get_def(search)
314
+ end
315
+ end
316
+
254
317
  pre do |global,command,options,args|
255
318
  # Pre logic here
256
319
  # Return true to proceed; false to abort and not call the
257
320
  # chosen command
258
321
  # Use skips_pre before a command to skip this block
259
322
  # on that command only
260
- wn = Lyracyst::Wordnik.new
323
+ if global[:o] != nil
324
+ outfile = global[:o]
325
+ if outfile =~ /\w*\.json/
326
+ $fmt = :json
327
+ elsif outfile =~ /\w*.xml/
328
+ $fmt = :xml
329
+ else
330
+ puts 'Invalid file extension.'
331
+ end
332
+ $tofile = []
333
+ end
261
334
  http = global[:h]
262
335
  json = global[:j]
263
336
  xml = global[:x]
264
337
  if http.class != Symbol then http = http.to_sym; end
265
- wn.set_http(http)
338
+ Lyracyst.set_http(http)
266
339
  if json.class != Symbol then json = json.to_sym; end
267
- wn.set_json(json)
340
+ Lyracyst.set_json(json)
268
341
  if xml.class != Symbol then xml = xml.to_sym; end
269
- wn.set_xml(xml)
342
+ Lyracyst.set_xml(xml)
270
343
  label = 'Global options'
271
- wn.label(label)
272
- print "- #{global} "
344
+ Lyracyst.label(label)
345
+ print "➜#{global}"
273
346
  label = 'Command'
274
- wn.label(label)
275
- print "- #{command.name} "
347
+ Lyracyst.label(label)
348
+ print "➜#{command.name}"
276
349
  label = 'Command options'
277
- wn.label(label)
278
- print "- #{options} "
350
+ Lyracyst.label(label)
351
+ print "➜#{options}"
279
352
  label = 'Args'
280
- wn.label(label)
281
- print "- #{args} "
353
+ Lyracyst.label(label)
354
+ print "➜#{args}"
282
355
  label = 'Bootstrapped'
283
- wn.label(label)
356
+ Lyracyst.label(label)
284
357
  puts ''
285
358
  true
286
359
  end
@@ -289,9 +362,61 @@ post do |global,command,options,args|
289
362
  # Post logic here
290
363
  # Use skips_post before a command to skip this
291
364
  # block on that command only
292
- wn = Lyracyst::Wordnik.new
293
- label = 'Shutdown'
294
- wn.label(label)
365
+ if $fmt != nil
366
+ outfile = global[:o]
367
+ if File.exist?(outfile) && global[:f] == true
368
+ if $fmt == :json
369
+ fo = File.open(outfile, 'w+')
370
+ fo.print MultiJson.dump($tofile)
371
+ fo.close
372
+ elsif $fmt == :xml
373
+ fo = File.open(outfile, 'w+')
374
+ fo.print '<?xml version="1.0" encoding="utf-8"?>'
375
+ fo.print XmlFu.xml($tofile)
376
+ fo.close
377
+ else
378
+ puts 'Invalid file extension.'
379
+ end
380
+ puts Rainbow("Word search was written to #{outfile}.").bright
381
+ end
382
+ if File.exist?(outfile) && global[:f] == false
383
+ puts Rainbow("#{outfile} exists. Overwrite? y/n ").bright
384
+ ans = gets
385
+ if ans =~ /y/
386
+ if $fmt == :json
387
+ fo = File.open(outfile, 'w+')
388
+ fo.print MultiJson.dump($tofile)
389
+ fo.close
390
+ elsif $fmt == :xml
391
+ fo = File.open(outfile, 'w+')
392
+ fo.print '<?xml version="1.0" encoding="utf-8"?>'
393
+ fo.print XmlFu.xml($tofile)
394
+ fo.close
395
+ else
396
+ puts 'Invalid file extension.'
397
+ end
398
+ puts Rainbow("Word search was written to #{outfile}.").bright
399
+ else
400
+ puts 'Please try again with a different filename.'
401
+ end
402
+ else
403
+ if $fmt == :json
404
+ fo = File.open(outfile, 'w+')
405
+ fo.print MultiJson.dump($tofile)
406
+ fo.close
407
+ elsif $fmt == :xml
408
+ fo = File.open(outfile, 'w+')
409
+ fo.print '<?xml version="1.0" encoding="utf-8"?>'
410
+ fo.print XmlFu.xml($tofile)
411
+ fo.close
412
+ else
413
+ puts 'Invalid file extension.'
414
+ end
415
+ puts Rainbow("Word search was written to #{outfile}.").bright
416
+ end
417
+ end
418
+ label = 'Shutdown'
419
+ Lyracyst.label(label)
295
420
  puts ''
296
421
  end
297
422
 
@@ -300,5 +425,4 @@ on_error do |exception|
300
425
  # return false to skip default error handling
301
426
  true
302
427
  end
303
-
304
428
  exit run(ARGV)