lyracyst 1.0.0 → 1.0.1

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: 7751d12d85b26befa84563c35152c9275f2603e3
4
- data.tar.gz: 719eead3fb8cf83e71643931abf11155ab8d657b
3
+ metadata.gz: e1a39a5e35076704944c2c416590f37cc8fbb1d6
4
+ data.tar.gz: 805cdc6ff1c12124f80f507d50c8f78e02467b82
5
5
  SHA512:
6
- metadata.gz: 27d43324ff46751095c76d121dfd47956659826c03bae613df1692cd5db92dd5f74a7a3efab892ffba905843999821b8e0f867f7d7a215fc92deaf7e32441e48
7
- data.tar.gz: 4113d612eb6cb24ba000e0e23023b15956c46cfc2f059c7a0fa5ea2233e17c4ff27324f44395ab851159bf87d9e744e2f1d9d856aa1eba99fb7c0d99f7a2dd91
6
+ metadata.gz: b843b137ae4f55980784dbf89c2eb0812e6caa1f90915bea222d5ac6a100c1f8f957d9fa3a01af02eaf9c64540a35b5edf2f1baa7de993a77addb4cd46d54cf8
7
+ data.tar.gz: 8bfd0f6ef818b3e11e85c56bffb9a69bf8a097c7a2a8550c0f084230b625b3f4d53d0a97fce36a99cfbccd8d1775640cfef3959eea0ed5a7d11ba6a9410fe7c3
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Changelog
2
2
  ===
3
3
 
4
+ Version 1.0.1 - Output file improvements
5
+ - Added search term to outfile
6
+ - Removed unnecessary duplication
7
+ - JSON files are pretty-generated.
8
+
4
9
  Version **1.0.0** - Subcommands, More options, Onelook
5
10
  - Added word info from [Onelook.com](http://www.onelook.com/?c=faq)
6
11
  - Added more CLI options
data/bin/lyracyst CHANGED
@@ -4,12 +4,15 @@
4
4
  # %w(json/ext json/pure multi_json oj yajl).map { |lib| require lib }
5
5
  # %w(libxml multi_xml ox rexml/document).map { |lib| require lib }
6
6
  require 'gli'
7
+ require 'httpi'
7
8
  require 'lyracyst/onelook'
8
9
  require 'lyracyst/rhymebrain'
9
10
  require 'lyracyst/urban'
10
11
  require 'lyracyst/version'
11
12
  require 'lyracyst/wordnik'
13
+ require "rexml/document"
12
14
  require 'xml-fu'
15
+ include REXML
13
16
 
14
17
  # The Lyracyst module handles base functionality.
15
18
  module Lyracyst
@@ -229,7 +232,7 @@ pre do |global, command, options, args|
229
232
  outfile = global[:o]
230
233
  if outfile =~ /\w*\.json/
231
234
  $fmt = :json
232
- elsif outfile =~ /\w*.xml/
235
+ elsif outfile =~ /\w*\.xml/
233
236
  $fmt = :xml
234
237
  else
235
238
  puts 'Invalid file extension.'
@@ -269,17 +272,18 @@ post do |global, command, options, args|
269
272
  if File.exist?(outfile) && global[:f] == true
270
273
  if $fmt == :json
271
274
  fo = File.open(outfile, 'w+')
272
- fo.print MultiJson.dump($tofile)
275
+ fo.print MultiJson.dump($tofile, :pretty => true)
273
276
  fo.close
277
+ puts Rainbow("Word search was written to #{outfile}.").bright
274
278
  elsif $fmt == :xml
275
279
  fo = File.open(outfile, 'w+')
276
280
  fo.print '<?xml version="1.0" encoding="utf-8"?>'
277
281
  fo.print XmlFu.xml($tofile)
278
282
  fo.close
283
+ puts Rainbow("Word search was written to #{outfile}.").bright
279
284
  else
280
285
  puts 'Invalid file extension.'
281
286
  end
282
- puts Rainbow("Word search was written to #{outfile}.").bright
283
287
  end
284
288
  if File.exist?(outfile) && global[:f] == false
285
289
  puts Rainbow("#{outfile} exists. Overwrite? y/n ").bright
@@ -287,34 +291,36 @@ post do |global, command, options, args|
287
291
  if ans =~ /y/
288
292
  if $fmt == :json
289
293
  fo = File.open(outfile, 'w+')
290
- fo.print MultiJson.dump($tofile)
294
+ fo.print MultiJson.dump($tofile, :pretty => true)
291
295
  fo.close
296
+ puts Rainbow("Word search was written to #{outfile}.").bright
292
297
  elsif $fmt == :xml
293
298
  fo = File.open(outfile, 'w+')
294
299
  fo.print '<?xml version="1.0" encoding="utf-8"?>'
295
300
  fo.print XmlFu.xml($tofile)
296
301
  fo.close
302
+ puts Rainbow("Word search was written to #{outfile}.").bright
297
303
  else
298
304
  puts 'Invalid file extension.'
299
305
  end
300
- puts Rainbow("Word search was written to #{outfile}.").bright
301
306
  else
302
307
  puts 'Please try again with a different filename.'
303
308
  end
304
309
  else
305
310
  if $fmt == :json
306
311
  fo = File.open(outfile, 'w+')
307
- fo.print MultiJson.dump($tofile)
312
+ fo.print MultiJson.dump($tofile, :pretty => true)
308
313
  fo.close
314
+ puts Rainbow("Word search was written to #{outfile}.").bright
309
315
  elsif $fmt == :xml
310
316
  fo = File.open(outfile, 'w+')
311
317
  fo.print '<?xml version="1.0" encoding="utf-8"?>'
312
318
  fo.print XmlFu.xml($tofile)
313
319
  fo.close
320
+ puts Rainbow("Word search was written to #{outfile}.").bright
314
321
  else
315
322
  puts 'Invalid file extension.'
316
323
  end
317
- puts Rainbow("Word search was written to #{outfile}.").bright
318
324
  end
319
325
  end
320
326
  if global[:v]
data/lib/lyracyst.rb CHANGED
@@ -4,12 +4,15 @@
4
4
  # %w(json/ext json/pure multi_json oj yajl).map { |lib| require lib }
5
5
  # %w(libxml multi_xml ox rexml/document).map { |lib| require lib }
6
6
  require 'gli'
7
+ require 'httpi'
7
8
  require 'lyracyst/onelook'
8
9
  require 'lyracyst/rhymebrain'
9
10
  require 'lyracyst/urban'
10
11
  require 'lyracyst/version'
11
12
  require 'lyracyst/wordnik'
13
+ require "rexml/document"
12
14
  require 'xml-fu'
15
+ include REXML
13
16
 
14
17
  # The Lyracyst module handles base functionality.
15
18
  module Lyracyst
@@ -229,7 +232,7 @@ pre do |global, command, options, args|
229
232
  outfile = global[:o]
230
233
  if outfile =~ /\w*\.json/
231
234
  $fmt = :json
232
- elsif outfile =~ /\w*.xml/
235
+ elsif outfile =~ /\w*\.xml/
233
236
  $fmt = :xml
234
237
  else
235
238
  puts 'Invalid file extension.'
@@ -269,17 +272,18 @@ post do |global, command, options, args|
269
272
  if File.exist?(outfile) && global[:f] == true
270
273
  if $fmt == :json
271
274
  fo = File.open(outfile, 'w+')
272
- fo.print MultiJson.dump($tofile)
275
+ fo.print MultiJson.dump($tofile, :pretty => true)
273
276
  fo.close
277
+ puts Rainbow("Word search was written to #{outfile}.").bright
274
278
  elsif $fmt == :xml
275
279
  fo = File.open(outfile, 'w+')
276
280
  fo.print '<?xml version="1.0" encoding="utf-8"?>'
277
281
  fo.print XmlFu.xml($tofile)
278
282
  fo.close
283
+ puts Rainbow("Word search was written to #{outfile}.").bright
279
284
  else
280
285
  puts 'Invalid file extension.'
281
286
  end
282
- puts Rainbow("Word search was written to #{outfile}.").bright
283
287
  end
284
288
  if File.exist?(outfile) && global[:f] == false
285
289
  puts Rainbow("#{outfile} exists. Overwrite? y/n ").bright
@@ -287,34 +291,36 @@ post do |global, command, options, args|
287
291
  if ans =~ /y/
288
292
  if $fmt == :json
289
293
  fo = File.open(outfile, 'w+')
290
- fo.print MultiJson.dump($tofile)
294
+ fo.print MultiJson.dump($tofile, :pretty => true)
291
295
  fo.close
296
+ puts Rainbow("Word search was written to #{outfile}.").bright
292
297
  elsif $fmt == :xml
293
298
  fo = File.open(outfile, 'w+')
294
299
  fo.print '<?xml version="1.0" encoding="utf-8"?>'
295
300
  fo.print XmlFu.xml($tofile)
296
301
  fo.close
302
+ puts Rainbow("Word search was written to #{outfile}.").bright
297
303
  else
298
304
  puts 'Invalid file extension.'
299
305
  end
300
- puts Rainbow("Word search was written to #{outfile}.").bright
301
306
  else
302
307
  puts 'Please try again with a different filename.'
303
308
  end
304
309
  else
305
310
  if $fmt == :json
306
311
  fo = File.open(outfile, 'w+')
307
- fo.print MultiJson.dump($tofile)
312
+ fo.print MultiJson.dump($tofile, :pretty => true)
308
313
  fo.close
314
+ puts Rainbow("Word search was written to #{outfile}.").bright
309
315
  elsif $fmt == :xml
310
316
  fo = File.open(outfile, 'w+')
311
317
  fo.print '<?xml version="1.0" encoding="utf-8"?>'
312
318
  fo.print XmlFu.xml($tofile)
313
319
  fo.close
320
+ puts Rainbow("Word search was written to #{outfile}.").bright
314
321
  else
315
322
  puts 'Invalid file extension.'
316
323
  end
317
- puts Rainbow("Word search was written to #{outfile}.").bright
318
324
  end
319
325
  end
320
326
  if global[:v]
@@ -24,18 +24,28 @@ module Lyracyst
24
24
  result = fe.get_word(search, result)
25
25
  result = MultiXml.parse(result)
26
26
  result = result['OLResponse']
27
+ st = { 'searchterm' => search }
28
+ Lyracyst.tofile(st)
29
+ t = { 'type' => 'look' }
30
+ Lyracyst.tofile(t)
27
31
  de, re, ph, si = result['OLQuickDef'], result['OLRes'], result['OLPhrases'].strip, result['OLSimilar'].strip
28
32
  de.map { |defi|
29
33
  Lyracyst.label('Definition')
30
34
  defi = defi.gsub(/&lt;i&gt;|&lt;\/i&gt;/, '')
35
+ d = { 'definition' => defi.strip }
36
+ Lyracyst.tofile(d)
31
37
  puts defi.strip
32
38
  }
33
39
  Lyracyst.label('Phrases')
34
40
  ph = ph.split(',')
35
41
  puts ph.join('|')
42
+ p = { 'phrases' => ph.join(',') }
43
+ Lyracyst.tofile(p)
36
44
  Lyracyst.label('Similar words')
37
45
  si = si.split(',')
38
46
  puts si.join('|')
47
+ s = { 'similar' => si.join(',') }
48
+ Lyracyst.tofile(s)
39
49
  if source
40
50
  fet = Lyracyst::Onelook::Fetch.new
41
51
  fet.get_src(re)
@@ -53,6 +63,12 @@ module Lyracyst
53
63
  hlink = res['OLResHomeLink'].strip
54
64
  Lyracyst.label('Resources')
55
65
  puts "#{name}|#{link}|#{hlink}"
66
+ n = { 'name' => name }
67
+ l = { 'link' => link }
68
+ hl = { 'hlink' => hlink }
69
+ Lyracyst.tofile(n)
70
+ Lyracyst.tofile(l)
71
+ Lyracyst.tofile(hl)
56
72
  x += 1
57
73
  end
58
74
  end
@@ -15,6 +15,8 @@ module Lyracyst
15
15
  if result != nil
16
16
  a, b, pmcont = 0, result.length - 1, []
17
17
  type = { 'type' => 'portmanteau' }
18
+ st = { 'searchterm' => search }
19
+ Lyracyst.tofile(st)
18
20
  Lyracyst.tofile(type)
19
21
  while a <= b
20
22
  match = result[a]
@@ -14,6 +14,8 @@ module Lyracyst
14
14
  result = MultiJson.load(result)
15
15
  if result != nil
16
16
  type = { 'type' => 'word info' }
17
+ st = { 'searchterm' => search }
18
+ Lyracyst.tofile(st)
17
19
  Lyracyst.tofile(type)
18
20
  word = result['word']
19
21
  pron = result['pron']
@@ -23,7 +25,7 @@ module Lyracyst
23
25
  Lyracyst.label(label)
24
26
  print Rainbow('Word|').bright
25
27
  print "#{word}"
26
- print Rainbow('|Pronunciation|').bright
28
+ print Rainbow('|ARPABET|').bright
27
29
  print "#{pron}"
28
30
  print Rainbow('|IPA|').bright
29
31
  print "#{ipa}"
@@ -31,7 +33,7 @@ module Lyracyst
31
33
  print "#{syllables}"
32
34
  print Rainbow('|Flags|').bright
33
35
  word = { 'word' => word }
34
- pron = { 'pronunciation' => pron }
36
+ pron = { 'ARPABET pronunciation' => pron }
35
37
  ipa = { 'IPA pronunciation' => ipa }
36
38
  syllables = { 'syllables' => syllables }
37
39
  Lyracyst.tofile(word)
@@ -15,6 +15,8 @@ module Lyracyst
15
15
  if result != nil
16
16
  a, b, rcont = 0, result.length - 1, []
17
17
  type = { 'type' => 'rhyme' }
18
+ st = { 'searchterm' => search }
19
+ Lyracyst.tofile(st)
18
20
  Lyracyst.tofile(type)
19
21
  while a <= b
20
22
  match = result[a]
@@ -27,6 +27,8 @@ module Lyracyst
27
27
  Lyracyst.label(label)
28
28
  print Rainbow("|Tags|#{tags}|Type|#{rtype}").bright
29
29
  x, y, dcont = 0, list.length - 1, []
30
+ st = { 'searchterm' => search }
31
+ Lyracyst.tofile(st)
30
32
  type = { 'type' => 'urban' }
31
33
  tags = { 'tags' => tags }
32
34
  rtype = { 'result type' => rtype }
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
  module Lyracyst
3
3
  # Semantic program version
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -23,6 +23,10 @@ module Lyracyst
23
23
  result = MultiJson.load(result)
24
24
  if result != nil
25
25
  x, y = 0, result.length - 1
26
+ st = { 'searchterm' => search }
27
+ type = { 'type' => 'definition' }
28
+ Lyracyst.tofile(st)
29
+ Lyracyst.tofile(type)
26
30
  while x <= y
27
31
  d = result[x]
28
32
  text = d['text']
@@ -30,10 +34,8 @@ module Lyracyst
30
34
  Lyracyst.label(label)
31
35
  print Rainbow("#{part}|").bright
32
36
  puts "#{text}|"
33
- type = { 'type' => 'definition' }
34
37
  part = { 'part' => part }
35
38
  text = { 'text' => text }
36
- Lyracyst.tofile(type)
37
39
  Lyracyst.tofile(part)
38
40
  Lyracyst.tofile(text)
39
41
  x += 1
@@ -15,19 +15,21 @@ module Lyracyst
15
15
  result = result['examples']
16
16
  if result != nil
17
17
  x, y = 0, result.length - 1
18
+ st = { 'searchterm' => search }
19
+ ty = { 'type' => 'example' }
20
+ Lyracyst.tofile(st)
21
+ Lyracyst.tofile(ty)
18
22
  while x <= y
19
23
  ex = result[x]
20
24
  title = ex['title']
21
25
  text = ex['text']
22
26
  url = ex['url']
23
27
  Lyracyst.label(label)
24
- print Rainbow("#{title}").bright
25
- puts "#{text}➜#{url}"
26
- ty = { 'type' => 'example' }
28
+ print Rainbow("#{title}|").bright
29
+ puts "#{text}|#{url}|"
27
30
  ti = { 'title' => title }
28
31
  te = { 'text' => text }
29
32
  u = { 'url' => url }
30
- Lyracyst.tofile(ty)
31
33
  Lyracyst.tofile(ti)
32
34
  Lyracyst.tofile(te)
33
35
  Lyracyst.tofile(u)
@@ -15,11 +15,13 @@ module Lyracyst
15
15
  if result != nil
16
16
  x, y, hcont = 0, result.length - 1, []
17
17
  Lyracyst.label(label)
18
+ t = { 'type' => 'hyphenation' }
19
+ st = { 'searchterm' => search }
20
+ Lyracyst.tofile(st)
21
+ Lyracyst.tofile(t)
18
22
  while x <= y
19
23
  hy = result[x]
20
24
  ht = hy['text']
21
- t = { 'type' => 'hyphenation' }
22
- Lyracyst.tofile(t)
23
25
  if hy['type'] == 'stress'
24
26
  stress = 'primary'
25
27
  sh = { ht => stress }
@@ -16,6 +16,8 @@ module Lyracyst
16
16
  result = MultiJson.load(result)
17
17
  a, b, cont = 0, result.length - 1, []
18
18
  type = { 'type' => 'etymology' }
19
+ st = { 'searchterm' => search }
20
+ Lyracyst.tofile(st)
19
21
  Lyracyst.tofile(type)
20
22
  while a <= b
21
23
  xml = result[a]
@@ -53,17 +55,15 @@ module Lyracyst
53
55
  if b == 0
54
56
  content = obj['__content__']
55
57
  container.push content
56
- node = { 'node' => content }
57
- Lyracyst.tofile(node)
58
58
  else
59
59
  content = obj[a]
60
60
  container.push content['__content__']
61
- node = { 'node' => content }
62
- Lyracyst.tofile(node)
63
61
  end
64
62
  a += 1
65
63
  end
66
64
  print "#{container.join('|')}"
65
+ node = { 'node' => container.join(',') }
66
+ Lyracyst.tofile(node)
67
67
  end
68
68
  end
69
69
  end
@@ -16,6 +16,8 @@ module Lyracyst
16
16
  x, y, phcont = 0, result.length - 1, []
17
17
  Lyracyst.label(label)
18
18
  type = { 'type' => 'phrase' }
19
+ st = { 'searchterm' => search }
20
+ Lyracyst.tofile(st)
19
21
  Lyracyst.tofile(type)
20
22
  while x <= y
21
23
  ph = result[x]
@@ -18,6 +18,8 @@ module Lyracyst
18
18
  if result != nil
19
19
  x, y = 0, result.length - 1
20
20
  type = { 'type' => 'pronunciation' }
21
+ st = { 'searchterm' => search }
22
+ Lyracyst.tofile(st)
21
23
  Lyracyst.tofile(type)
22
24
  while x <= y
23
25
  pro = result[x]
@@ -26,7 +28,7 @@ module Lyracyst
26
28
  Lyracyst.label(label)
27
29
  puts "#{raw}|#{rawtype}|"
28
30
  pronunciation = { 'pronunciation' => raw }
29
- ptype = { 'type' => rawtype }
31
+ ptype = { 'ptype' => rawtype }
30
32
  Lyracyst.tofile(pronunciation)
31
33
  Lyracyst.tofile(ptype)
32
34
  x += 1
@@ -21,6 +21,8 @@ module Lyracyst
21
21
  if result != nil
22
22
  x, y = 0, result.length - 1
23
23
  type = { 'type' => 'related words' }
24
+ st = { 'searchterm' => search }
25
+ Lyracyst.tofile(st)
24
26
  Lyracyst.tofile(type)
25
27
  while x <= y
26
28
  re = result[x]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lyracyst
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Prentice
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.10'
19
+ version: '2.11'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.10'
26
+ version: '2.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: httpi
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.9'
47
+ version: '1.10'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.9'
54
+ version: '1.10'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: multi_xml
57
57
  requirement: !ruby/object:Gem::Requirement