lyracyst 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1a39a5e35076704944c2c416590f37cc8fbb1d6
4
- data.tar.gz: 805cdc6ff1c12124f80f507d50c8f78e02467b82
3
+ metadata.gz: 04aa0f88e802ebfc29567e7bd4c869217ecccc0b
4
+ data.tar.gz: ca44ce70517f1d47ba7a42ebdcc5c0b213362d04
5
5
  SHA512:
6
- metadata.gz: b843b137ae4f55980784dbf89c2eb0812e6caa1f90915bea222d5ac6a100c1f8f957d9fa3a01af02eaf9c64540a35b5edf2f1baa7de993a77addb4cd46d54cf8
7
- data.tar.gz: 8bfd0f6ef818b3e11e85c56bffb9a69bf8a097c7a2a8550c0f084230b625b3f4d53d0a97fce36a99cfbccd8d1775640cfef3959eea0ed5a7d11ba6a9410fe7c3
6
+ metadata.gz: 955927f012089dea86c66eceb908d42913955622a463ddef9b6d3e58741ec3eec287bf840ed13d4447decf93173f6c4e9b9b9764aa686263a9b640c07d0fb915
7
+ data.tar.gz: 9db35817730ca71a25601bee00fa94a731c19707bba84db06132ab6bc012dd56e9b303680e7b1228b1613c838af07ef712ce8db60b0c22a9c4fe7b424d3b19bb
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Changelog
2
2
  ===
3
3
 
4
+ Version 1.0.2 - Code climate & defaults
5
+ - Methodized more code blocks to improve climate
6
+ - Now using smart defaults for httpi, multi_json & multi_xml
7
+
4
8
  Version 1.0.1 - Output file improvements
5
9
  - Added search term to outfile
6
10
  - Removed unnecessary duplication
data/bin/lyracyst CHANGED
@@ -67,24 +67,23 @@ program_desc 'A powerful word search tool that fetches definitions, related word
67
67
  config_file '.lyracyst.yml'
68
68
  version Lyracyst::VERSION
69
69
 
70
- flag [:f, :format], :default_value => nil, :arg_name => 'fmt', :desc => 'File format', :long_desc => 'json or xml'
71
- flag [:h, :http], :default_value => :net_http_persistent, :arg_name => 'http', :desc => 'HTTP adapter', :long_desc => 'httpclient, curb, em_http, net_http_persistent, excon, rack'
72
- flag [:j, :json], :default_value => :oj, :arg_name => 'json', :desc => 'JSON adapter', :long_desc => 'oj, yajl, json_gem, json_pure'
73
- flag [:o, :out], :default_value => nil, :arg_name => 'outfile', :desc => 'Output file', :long_desc => 'filename.json or filename.xml'
74
- flag [:x, :xml], :default_value => :rexml, :arg_name => 'xml', :desc => 'XML adapter', :long_desc => 'ox, libxml, nokogiri, rexml'
70
+ flag [:f, :format], :default_value => nil, :arg_name => 'string', :desc => 'File format', :long_desc => 'json or xml'
71
+ flag [:h, :http], :default_value => nil, :arg_name => 'string', :desc => 'HTTP adapter', :long_desc => 'httpclient, curb, em_http, net_http_persistent, excon, rack'
72
+ flag [:j, :json], :default_value => nil, :arg_name => 'string', :desc => 'JSON adapter', :long_desc => 'oj, yajl, json_gem, json_pure'
73
+ flag [:o, :out], :default_value => nil, :arg_name => 'filename', :desc => 'Output file', :long_desc => 'filename.json or filename.xml'
74
+ flag [:x, :xml], :default_value => nil, :arg_name => 'string', :desc => 'XML adapter', :long_desc => 'ox, libxml, nokogiri, rexml'
75
75
  switch [:fo, :force], :default_value => false, :desc => 'Force overwrite', :long_desc => 'Overwrites existing JSON & XML files'
76
76
  switch [:v, :verbose], :default_value => false, :desc => 'Prints parameters and options'
77
77
 
78
78
  desc 'Wordnik operations'
79
- arg_name 'wordnik'
80
79
  command :wn do |nik|
81
80
  nik.switch :canon, :default_value => false, :desc => 'Use canonical', :long_desc => "If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested."
82
- nik.flag :limit, :default_value => 5, :arg_name => 'limit', :desc => 'Maximum number of results to return'
81
+ nik.flag :limit, :default_value => 5, :arg_name => 'integer', :desc => 'Maximum number of results to return'
83
82
  nik.desc 'Fetch definitions from Wordnik'
84
- nik.arg_name 'define'
83
+ nik.arg_name 'word'
85
84
  nik.command :def do |define|
86
- define.flag :defdict, :default_value => 'all', :arg_name => 'defdict', :desc => "CSV list. Source dictionaries to return definitions from. If 'all' is received, results are returned from all sources. If multiple values are received (e.g. 'century,wiktionary'), results are returned from the first specified dictionary that has definitions. If left blank, results are returned from the first dictionary that has definitions. By default, dictionaries are searched in this order: ahd, wiktionary, webster, century, wordnet"
87
- define.flag [:p, :part], :default_value => nil, :arg_name => 'part', :desc => 'Comma-separated list of parts of speech. See http://developer.wordnik.com/docs.html#!/word/getDefinitions_get_2 for list of parts.'
85
+ define.flag :defdict, :default_value => 'all', :arg_name => 'string', :desc => "CSV list. Source dictionaries to return definitions from. If 'all' is received, results are returned from all sources. If multiple values are received (e.g. 'century,wiktionary'), results are returned from the first specified dictionary that has definitions. If left blank, results are returned from the first dictionary that has definitions. By default, dictionaries are searched in this order: ahd, wiktionary, webster, century, wordnet"
86
+ define.flag [:p, :part], :default_value => nil, :arg_name => 'csv', :desc => 'Comma-separated list of parts of speech. See http://developer.wordnik.com/docs.html#!/word/getDefinitions_get_2 for list of parts.'
88
87
  define.action do |global_options, options, args|
89
88
  search = args[0]
90
89
  params = { canon: options[:canon], defdict: options[:defdict], increl: false, inctags: false, limit: options[:limit] }
@@ -93,9 +92,9 @@ command :wn do |nik|
93
92
  end
94
93
  end
95
94
  nik.desc 'Fetch examples from Wordnik'
96
- nik.arg_name 'example'
95
+ nik.arg_name 'word'
97
96
  nik.command :ex do |example|
98
- example.flag [:s, :skip], :default_value => 0, :arg_name => 'skip', :desc => 'Results to skip'
97
+ example.flag [:s, :skip], :default_value => 0, :arg_name => 'integer', :desc => 'Results to skip'
99
98
  example.switch :incdups, :default_value => false, :desc => 'Show duplicate examples from different sources'
100
99
  example.action do |global_options, options, args|
101
100
  search = args[0]
@@ -105,10 +104,10 @@ command :wn do |nik|
105
104
  end
106
105
  end
107
106
  nik.desc 'Fetches related words from Wordnik'
108
- nik.arg_name 'relate'
107
+ nik.arg_name 'word'
109
108
  nik.command :rel do |relate|
110
- relate.flag :relt, :default_value => nil, :arg_name => 'reltypes', :desc => 'Limits the total results per type of relationship type'
111
- relate.flag :rell, :default_value => 10, :arg_name => 'rell', :desc => 'Restrict to the supplied relationship types'
109
+ relate.flag :relt, :default_value => nil, :arg_name => 'integer', :desc => 'Limits the total results per type of relationship type'
110
+ relate.flag :rell, :default_value => 10, :arg_name => 'integer', :desc => 'Restrict to the supplied relationship types'
112
111
  relate.action do |global_options, options, args|
113
112
  search = args[0]
114
113
  params = { canon: options[:canon], rellimit: options[:rell] }
@@ -117,10 +116,10 @@ command :wn do |nik|
117
116
  end
118
117
  end
119
118
  nik.desc 'Fetches pronunciations from Wordnik'
120
- nik.arg_name 'pronounce'
119
+ nik.arg_name 'word'
121
120
  nik.command :pro do |pronounce|
122
- pronounce.flag :src, :default_value => nil, :arg_name => 'source', :desc =>'Get from a single dictionary. Valid options: ahd, century, cmu, macmillan, wiktionary, webster, or wordnet'
123
- pronounce.flag :pt, :default_value => nil, :arg_name => 'ptype', :desc => 'Text pronunciation type', :long_desc => 'ahd, arpabet, gcide-diacritical, IPA'
121
+ pronounce.flag :src, :default_value => nil, :arg_name => 'string', :desc =>'Get from a single dictionary. Valid options: ahd, century, cmu, macmillan, wiktionary, webster, or wordnet'
122
+ pronounce.flag :pt, :default_value => nil, :arg_name => 'string', :desc => 'Text pronunciation type', :long_desc => 'ahd, arpabet, gcide-diacritical, IPA'
124
123
  pronounce.action do |global_options, options, args|
125
124
  search = args[0]
126
125
  params = { canon: options[:canon], limit: options[:limit], source: options[:src] }
@@ -129,9 +128,9 @@ command :wn do |nik|
129
128
  end
130
129
  end
131
130
  nik.desc 'Fetches hyphenation and syllable stresses from Wordnik. Primary stress is red, secondary stress is bright white.'
132
- nik.arg_name 'hyphen'
131
+ nik.arg_name 'word'
133
132
  nik.command :hyph do |hyphen|
134
- hyphen.flag :source, :default_value => nil, :arg_name => 'source', :desc => "Get from a single dictionary. Valid options: ahd, century, wiktionary, webster, and wordnet."
133
+ hyphen.flag :source, :default_value => nil, :arg_name => 'string', :desc => "Get from a single dictionary. Valid options: ahd, century, wiktionary, webster, and wordnet."
135
134
  hyphen.action do |global_options, options, args|
136
135
  search = args[0]
137
136
  params = { canon: options[:canon], limit: options[:limit] }
@@ -141,9 +140,9 @@ command :wn do |nik|
141
140
  end
142
141
  end
143
142
  nik.desc 'Fetches bi-gram phrases from Wordnik'
144
- nik.arg_name 'phrase'
143
+ nik.arg_name 'word'
145
144
  nik.command :phr do |phrase|
146
- phrase.flag :wlmi, :default_value => 13, :arg_name => 'wlmi', :desc => 'Minimum WLMI(weighted mutual info) for the phrase.'
145
+ phrase.flag :wlmi, :default_value => 13, :arg_name => 'integer', :desc => 'Minimum WLMI(weighted mutual info) for the phrase.'
147
146
  phrase.action do |global_options, options, args|
148
147
  search = args[0]
149
148
  params = { canon: options[:canon], limit: options[:limit], wlmi: options[:wlmi] }
@@ -152,7 +151,7 @@ command :wn do |nik|
152
151
  end
153
152
  end
154
153
  nik.desc 'Fetches etymologies from Wordnik'
155
- nik.arg_name 'origin'
154
+ nik.arg_name 'word'
156
155
  nik.command :ori do |origin|
157
156
  origin.action do |global_options, options, args|
158
157
  search = args[0]
@@ -164,12 +163,11 @@ command :wn do |nik|
164
163
  end
165
164
 
166
165
  desc 'Rhymebrain operations'
167
- arg_name 'rhymebrain'
168
166
  command :rb do |rb|
169
- rb.flag :lang, :default_value => 'en', :arg_name => 'lang', :desc => 'ISO639-1 language code (optional). Eg. en, de, es, fr, ru'
170
- rb.flag :max, :default_value => nil, :arg_name => 'max', :desc => '(optional) The number of results to return. If you do not include this parameter, RhymeBrain will choose how many words to show based on how many good sounding rhymes there are for the word.'
167
+ rb.flag :lang, :default_value => 'en', :arg_name => 'string', :desc => 'ISO639-1 language code (optional). Eg. en, de, es, fr, ru'
168
+ rb.flag :max, :default_value => nil, :arg_name => 'integer', :desc => '(optional) The number of results to return. If you do not include this parameter, RhymeBrain will choose how many words to show based on how many good sounding rhymes there are for the word.'
171
169
  rb.desc 'Fetches rhymes from Rhymebrain.com'
172
- rb.arg_name 'rhyme'
170
+ rb.arg_name 'word'
173
171
  rb.command :rhy do |rhyme|
174
172
  rhyme.action do |global_options, options, args|
175
173
  search = args[0]
@@ -179,7 +177,7 @@ command :rb do |rb|
179
177
  end
180
178
  end
181
179
  rb.desc 'Fetches word info from Rhymebrain.com'
182
- rb.arg_name 'info'
180
+ rb.arg_name 'word'
183
181
  rb.command :inf do |info|
184
182
  info.action do |global_options, options, args|
185
183
  search = args[0]
@@ -189,7 +187,7 @@ command :rb do |rb|
189
187
  end
190
188
  end
191
189
  rb.desc 'Fetches combined words (portmanteaus) from Rhymebrain.com'
192
- rb.arg_name 'combine'
190
+ rb.arg_name 'word'
193
191
  rb.command :comb do |combine|
194
192
  combine.action do |global_options, options, args|
195
193
  search = args[0]
@@ -242,12 +240,18 @@ pre do |global, command, options, args|
242
240
  http = global[:h]
243
241
  json = global[:j]
244
242
  xml = global[:x]
245
- if http.class != Symbol then http = http.to_sym; end
246
- Lyracyst.http(http)
247
- if json.class != Symbol then json = json.to_sym; end
248
- Lyracyst.json(json)
249
- if xml.class != Symbol then xml = xml.to_sym; end
250
- Lyracyst.xml(xml)
243
+ if http != nil
244
+ if http.class != Symbol then http = http.to_sym; end
245
+ Lyracyst.http(http)
246
+ end
247
+ if json != nil
248
+ if json.class != Symbol then json = json.to_sym; end
249
+ Lyracyst.json(json)
250
+ end
251
+ if xml != nil
252
+ if xml.class != Symbol then xml = xml.to_sym; end
253
+ Lyracyst.xml(xml)
254
+ end
251
255
  if global[:v]
252
256
  Lyracyst.label('Global options')
253
257
  print "#{global}"
data/lib/lyracyst.rb CHANGED
@@ -67,24 +67,23 @@ program_desc 'A powerful word search tool that fetches definitions, related word
67
67
  config_file '.lyracyst.yml'
68
68
  version Lyracyst::VERSION
69
69
 
70
- flag [:f, :format], :default_value => nil, :arg_name => 'fmt', :desc => 'File format', :long_desc => 'json or xml'
71
- flag [:h, :http], :default_value => :net_http_persistent, :arg_name => 'http', :desc => 'HTTP adapter', :long_desc => 'httpclient, curb, em_http, net_http_persistent, excon, rack'
72
- flag [:j, :json], :default_value => :oj, :arg_name => 'json', :desc => 'JSON adapter', :long_desc => 'oj, yajl, json_gem, json_pure'
73
- flag [:o, :out], :default_value => nil, :arg_name => 'outfile', :desc => 'Output file', :long_desc => 'filename.json or filename.xml'
74
- flag [:x, :xml], :default_value => :rexml, :arg_name => 'xml', :desc => 'XML adapter', :long_desc => 'ox, libxml, nokogiri, rexml'
70
+ flag [:f, :format], :default_value => nil, :arg_name => 'string', :desc => 'File format', :long_desc => 'json or xml'
71
+ flag [:h, :http], :default_value => nil, :arg_name => 'string', :desc => 'HTTP adapter', :long_desc => 'httpclient, curb, em_http, net_http_persistent, excon, rack'
72
+ flag [:j, :json], :default_value => nil, :arg_name => 'string', :desc => 'JSON adapter', :long_desc => 'oj, yajl, json_gem, json_pure'
73
+ flag [:o, :out], :default_value => nil, :arg_name => 'filename', :desc => 'Output file', :long_desc => 'filename.json or filename.xml'
74
+ flag [:x, :xml], :default_value => nil, :arg_name => 'string', :desc => 'XML adapter', :long_desc => 'ox, libxml, nokogiri, rexml'
75
75
  switch [:fo, :force], :default_value => false, :desc => 'Force overwrite', :long_desc => 'Overwrites existing JSON & XML files'
76
76
  switch [:v, :verbose], :default_value => false, :desc => 'Prints parameters and options'
77
77
 
78
78
  desc 'Wordnik operations'
79
- arg_name 'wordnik'
80
79
  command :wn do |nik|
81
80
  nik.switch :canon, :default_value => false, :desc => 'Use canonical', :long_desc => "If true will try to return the correct word root ('cats' -> 'cat'). If false returns exactly what was requested."
82
- nik.flag :limit, :default_value => 5, :arg_name => 'limit', :desc => 'Maximum number of results to return'
81
+ nik.flag :limit, :default_value => 5, :arg_name => 'integer', :desc => 'Maximum number of results to return'
83
82
  nik.desc 'Fetch definitions from Wordnik'
84
- nik.arg_name 'define'
83
+ nik.arg_name 'word'
85
84
  nik.command :def do |define|
86
- define.flag :defdict, :default_value => 'all', :arg_name => 'defdict', :desc => "CSV list. Source dictionaries to return definitions from. If 'all' is received, results are returned from all sources. If multiple values are received (e.g. 'century,wiktionary'), results are returned from the first specified dictionary that has definitions. If left blank, results are returned from the first dictionary that has definitions. By default, dictionaries are searched in this order: ahd, wiktionary, webster, century, wordnet"
87
- define.flag [:p, :part], :default_value => nil, :arg_name => 'part', :desc => 'Comma-separated list of parts of speech. See http://developer.wordnik.com/docs.html#!/word/getDefinitions_get_2 for list of parts.'
85
+ define.flag :defdict, :default_value => 'all', :arg_name => 'string', :desc => "CSV list. Source dictionaries to return definitions from. If 'all' is received, results are returned from all sources. If multiple values are received (e.g. 'century,wiktionary'), results are returned from the first specified dictionary that has definitions. If left blank, results are returned from the first dictionary that has definitions. By default, dictionaries are searched in this order: ahd, wiktionary, webster, century, wordnet"
86
+ define.flag [:p, :part], :default_value => nil, :arg_name => 'csv', :desc => 'Comma-separated list of parts of speech. See http://developer.wordnik.com/docs.html#!/word/getDefinitions_get_2 for list of parts.'
88
87
  define.action do |global_options, options, args|
89
88
  search = args[0]
90
89
  params = { canon: options[:canon], defdict: options[:defdict], increl: false, inctags: false, limit: options[:limit] }
@@ -93,9 +92,9 @@ command :wn do |nik|
93
92
  end
94
93
  end
95
94
  nik.desc 'Fetch examples from Wordnik'
96
- nik.arg_name 'example'
95
+ nik.arg_name 'word'
97
96
  nik.command :ex do |example|
98
- example.flag [:s, :skip], :default_value => 0, :arg_name => 'skip', :desc => 'Results to skip'
97
+ example.flag [:s, :skip], :default_value => 0, :arg_name => 'integer', :desc => 'Results to skip'
99
98
  example.switch :incdups, :default_value => false, :desc => 'Show duplicate examples from different sources'
100
99
  example.action do |global_options, options, args|
101
100
  search = args[0]
@@ -105,10 +104,10 @@ command :wn do |nik|
105
104
  end
106
105
  end
107
106
  nik.desc 'Fetches related words from Wordnik'
108
- nik.arg_name 'relate'
107
+ nik.arg_name 'word'
109
108
  nik.command :rel do |relate|
110
- relate.flag :relt, :default_value => nil, :arg_name => 'reltypes', :desc => 'Limits the total results per type of relationship type'
111
- relate.flag :rell, :default_value => 10, :arg_name => 'rell', :desc => 'Restrict to the supplied relationship types'
109
+ relate.flag :relt, :default_value => nil, :arg_name => 'integer', :desc => 'Limits the total results per type of relationship type'
110
+ relate.flag :rell, :default_value => 10, :arg_name => 'integer', :desc => 'Restrict to the supplied relationship types'
112
111
  relate.action do |global_options, options, args|
113
112
  search = args[0]
114
113
  params = { canon: options[:canon], rellimit: options[:rell] }
@@ -117,10 +116,10 @@ command :wn do |nik|
117
116
  end
118
117
  end
119
118
  nik.desc 'Fetches pronunciations from Wordnik'
120
- nik.arg_name 'pronounce'
119
+ nik.arg_name 'word'
121
120
  nik.command :pro do |pronounce|
122
- pronounce.flag :src, :default_value => nil, :arg_name => 'source', :desc =>'Get from a single dictionary. Valid options: ahd, century, cmu, macmillan, wiktionary, webster, or wordnet'
123
- pronounce.flag :pt, :default_value => nil, :arg_name => 'ptype', :desc => 'Text pronunciation type', :long_desc => 'ahd, arpabet, gcide-diacritical, IPA'
121
+ pronounce.flag :src, :default_value => nil, :arg_name => 'string', :desc =>'Get from a single dictionary. Valid options: ahd, century, cmu, macmillan, wiktionary, webster, or wordnet'
122
+ pronounce.flag :pt, :default_value => nil, :arg_name => 'string', :desc => 'Text pronunciation type', :long_desc => 'ahd, arpabet, gcide-diacritical, IPA'
124
123
  pronounce.action do |global_options, options, args|
125
124
  search = args[0]
126
125
  params = { canon: options[:canon], limit: options[:limit], source: options[:src] }
@@ -129,9 +128,9 @@ command :wn do |nik|
129
128
  end
130
129
  end
131
130
  nik.desc 'Fetches hyphenation and syllable stresses from Wordnik. Primary stress is red, secondary stress is bright white.'
132
- nik.arg_name 'hyphen'
131
+ nik.arg_name 'word'
133
132
  nik.command :hyph do |hyphen|
134
- hyphen.flag :source, :default_value => nil, :arg_name => 'source', :desc => "Get from a single dictionary. Valid options: ahd, century, wiktionary, webster, and wordnet."
133
+ hyphen.flag :source, :default_value => nil, :arg_name => 'string', :desc => "Get from a single dictionary. Valid options: ahd, century, wiktionary, webster, and wordnet."
135
134
  hyphen.action do |global_options, options, args|
136
135
  search = args[0]
137
136
  params = { canon: options[:canon], limit: options[:limit] }
@@ -141,9 +140,9 @@ command :wn do |nik|
141
140
  end
142
141
  end
143
142
  nik.desc 'Fetches bi-gram phrases from Wordnik'
144
- nik.arg_name 'phrase'
143
+ nik.arg_name 'word'
145
144
  nik.command :phr do |phrase|
146
- phrase.flag :wlmi, :default_value => 13, :arg_name => 'wlmi', :desc => 'Minimum WLMI(weighted mutual info) for the phrase.'
145
+ phrase.flag :wlmi, :default_value => 13, :arg_name => 'integer', :desc => 'Minimum WLMI(weighted mutual info) for the phrase.'
147
146
  phrase.action do |global_options, options, args|
148
147
  search = args[0]
149
148
  params = { canon: options[:canon], limit: options[:limit], wlmi: options[:wlmi] }
@@ -152,7 +151,7 @@ command :wn do |nik|
152
151
  end
153
152
  end
154
153
  nik.desc 'Fetches etymologies from Wordnik'
155
- nik.arg_name 'origin'
154
+ nik.arg_name 'word'
156
155
  nik.command :ori do |origin|
157
156
  origin.action do |global_options, options, args|
158
157
  search = args[0]
@@ -164,12 +163,11 @@ command :wn do |nik|
164
163
  end
165
164
 
166
165
  desc 'Rhymebrain operations'
167
- arg_name 'rhymebrain'
168
166
  command :rb do |rb|
169
- rb.flag :lang, :default_value => 'en', :arg_name => 'lang', :desc => 'ISO639-1 language code (optional). Eg. en, de, es, fr, ru'
170
- rb.flag :max, :default_value => nil, :arg_name => 'max', :desc => '(optional) The number of results to return. If you do not include this parameter, RhymeBrain will choose how many words to show based on how many good sounding rhymes there are for the word.'
167
+ rb.flag :lang, :default_value => 'en', :arg_name => 'string', :desc => 'ISO639-1 language code (optional). Eg. en, de, es, fr, ru'
168
+ rb.flag :max, :default_value => nil, :arg_name => 'integer', :desc => '(optional) The number of results to return. If you do not include this parameter, RhymeBrain will choose how many words to show based on how many good sounding rhymes there are for the word.'
171
169
  rb.desc 'Fetches rhymes from Rhymebrain.com'
172
- rb.arg_name 'rhyme'
170
+ rb.arg_name 'word'
173
171
  rb.command :rhy do |rhyme|
174
172
  rhyme.action do |global_options, options, args|
175
173
  search = args[0]
@@ -179,7 +177,7 @@ command :rb do |rb|
179
177
  end
180
178
  end
181
179
  rb.desc 'Fetches word info from Rhymebrain.com'
182
- rb.arg_name 'info'
180
+ rb.arg_name 'word'
183
181
  rb.command :inf do |info|
184
182
  info.action do |global_options, options, args|
185
183
  search = args[0]
@@ -189,7 +187,7 @@ command :rb do |rb|
189
187
  end
190
188
  end
191
189
  rb.desc 'Fetches combined words (portmanteaus) from Rhymebrain.com'
192
- rb.arg_name 'combine'
190
+ rb.arg_name 'word'
193
191
  rb.command :comb do |combine|
194
192
  combine.action do |global_options, options, args|
195
193
  search = args[0]
@@ -242,12 +240,18 @@ pre do |global, command, options, args|
242
240
  http = global[:h]
243
241
  json = global[:j]
244
242
  xml = global[:x]
245
- if http.class != Symbol then http = http.to_sym; end
246
- Lyracyst.http(http)
247
- if json.class != Symbol then json = json.to_sym; end
248
- Lyracyst.json(json)
249
- if xml.class != Symbol then xml = xml.to_sym; end
250
- Lyracyst.xml(xml)
243
+ if http != nil
244
+ if http.class != Symbol then http = http.to_sym; end
245
+ Lyracyst.http(http)
246
+ end
247
+ if json != nil
248
+ if json.class != Symbol then json = json.to_sym; end
249
+ Lyracyst.json(json)
250
+ end
251
+ if xml != nil
252
+ if xml.class != Symbol then xml = xml.to_sym; end
253
+ Lyracyst.xml(xml)
254
+ end
251
255
  if global[:v]
252
256
  Lyracyst.label('Global options')
253
257
  print "#{global}"
@@ -1,9 +1,9 @@
1
1
  %w{httpi multi_xml rainbow}.map { |lib| require lib }
2
2
  module Lyracyst
3
- # Fetches definitions, phrases, similar words, and resource links from Onelook
3
+ # Fetches definitions, phrases, similar words, and resource links from Onelook.
4
4
  class Onelook
5
- # @param search [String] The term to search for
6
- # @param search [String] The XML response
5
+ # @param search [String] The term to search for.
6
+ # @param search [String] The XML response.
7
7
  def get_word(search, result)
8
8
  prefix = 'http://www.onelook.com/?xml=1&w='
9
9
  url = "#{prefix}#{search}"
@@ -11,12 +11,12 @@ module Lyracyst
11
11
  getter = HTTPI.get(request)
12
12
  result = getter.body
13
13
  end
14
- # Fetches and processes URL
14
+ # Fetches and processes URL.
15
15
  class Fetch
16
16
  # Main operations. Resource links are off by default.
17
17
  #
18
- # @param search [String] The term to search for
19
- # @param source [Boolean] Whether to print resource links (verbose)
18
+ # @param search [String] The term to search for.
19
+ # @param source [Boolean] Whether to print resource links (verbose).
20
20
  def fetch(search, source)
21
21
  label, result = 'Onelook', nil
22
22
  Lyracyst.label(label)
@@ -53,7 +53,7 @@ module Lyracyst
53
53
  end
54
54
  # Get resource links.
55
55
  #
56
- # @param re [Array] Array of resource hashes
56
+ # @param re [Array] Array of resource hashes.
57
57
  def get_src(re)
58
58
  x, y = 0, re.length - 1
59
59
  while x <= y
@@ -8,32 +8,39 @@ module Lyracyst
8
8
  # @param search [String] The word or phrase to search for.
9
9
  # @param params [Hash] The search parameters to use.
10
10
  def get_port(search, params)
11
- func, label, result = 'Portmanteaus', 'Portmanteaus', nil
11
+ func, result = 'Portmanteaus', nil
12
12
  pm = Lyracyst::Rhymebrain.new
13
13
  result = pm.get_word(search, func, params, result)
14
14
  result = MultiJson.load(result)
15
15
  if result != nil
16
- a, b, pmcont = 0, result.length - 1, []
17
16
  type = { 'type' => 'portmanteau' }
18
17
  st = { 'searchterm' => search }
19
18
  Lyracyst.tofile(st)
20
19
  Lyracyst.tofile(type)
21
- while a <= b
22
- match = result[a]
23
- roots = match['source']
24
- combo = match['combined']
25
- both = "#{Rainbow('Root words|').bright}#{roots}#{Rainbow('Combination|').bright}#{combo}"
26
- roots = { 'roots' => roots }
27
- combo = { 'combo' => combo }
28
- Lyracyst.tofile(roots)
29
- Lyracyst.tofile(combo)
30
- pmcont.push both
31
- a += 1
32
- end
33
- Lyracyst.label(label)
34
- puts pmcont.join(Rainbow('|').bright)
20
+ e = Lyracyst::Rhymebrain::Combine.new
21
+ e.comb_extra(result)
35
22
  end
36
23
  end
24
+ # Extra repetitive tasks
25
+ #
26
+ # @param result [Array] List of hashes to process.
27
+ def comb_extra(result)
28
+ a, b, pmcont, label = 0, result.length - 1, [], 'Portmanteau'
29
+ while a <= b
30
+ match = result[a]
31
+ roots = match['source']
32
+ combo = match['combined']
33
+ both = "#{Rainbow('Root words|').bright}#{roots}#{Rainbow('Combination|').bright}#{combo}"
34
+ roots = { 'roots' => roots }
35
+ combo = { 'combo' => combo }
36
+ Lyracyst.tofile(roots)
37
+ Lyracyst.tofile(combo)
38
+ pmcont.push both
39
+ a += 1
40
+ end
41
+ Lyracyst.label(label)
42
+ puts pmcont.join(Rainbow('|').bright)
43
+ end
37
44
  end
38
45
  end
39
46
  end
@@ -13,51 +13,65 @@ module Lyracyst
13
13
  result = wi.get_word(search, func, params, result)
14
14
  result = MultiJson.load(result)
15
15
  if result != nil
16
+ Lyracyst.label(label)
16
17
  type = { 'type' => 'word info' }
17
18
  st = { 'searchterm' => search }
18
19
  Lyracyst.tofile(st)
19
20
  Lyracyst.tofile(type)
20
- word = result['word']
21
- pron = result['pron']
22
- ipa = result['ipa']
23
- flags = result['flags']
24
- syllables = result['syllables']
25
- Lyracyst.label(label)
26
- print Rainbow('Word|').bright
27
- print "#{word}"
28
- print Rainbow('|ARPABET|').bright
29
- print "#{pron}"
30
- print Rainbow('|IPA|').bright
31
- print "#{ipa}"
32
- print Rainbow('|Syllables|').bright
33
- print "#{syllables}"
34
- print Rainbow('|Flags|').bright
35
- word = { 'word' => word }
36
- pron = { 'ARPABET pronunciation' => pron }
37
- ipa = { 'IPA pronunciation' => ipa }
38
- syllables = { 'syllables' => syllables }
39
- Lyracyst.tofile(word)
40
- Lyracyst.tofile(pron)
41
- Lyracyst.tofile(ipa)
42
- Lyracyst.tofile(syllables)
43
- fcont = []
44
- if flags =~ /a/
45
- fcont.push Rainbow('The word is offensive.').red.bright
46
- flag = { 'aflag' => 'The word is offensive.' }
47
- Lyracyst.tofile(flag)
48
- end
49
- if flags =~ /b/
50
- fcont.push 'The word might be found in most dictionaries.'
51
- flag = { 'bflag' => 'The word might be found in most dictionaries.' }
52
- Lyracyst.tofile(flag)
53
- end
54
- if flags =~ /c/
55
- fcont.push 'The pronunciation is known with confidence. It was not automatically generated.'
56
- flag = { 'cflag' => 'The pronunciation is known with confidence. It was not automatically generated.' }
57
- Lyracyst.tofile(flag)
58
- end
59
- puts "#{fcont.join(Rainbow('|').bright)}"
21
+ e = Lyracyst::Rhymebrain::Info.new
22
+ e.info_extra(result)
23
+ end
24
+ end
25
+ # Extra repetitive taks.
26
+ #
27
+ # @param result [Array] Hash to process.
28
+ def info_extra(result)
29
+ word = result['word']
30
+ pron = result['pron']
31
+ ipa = result['ipa']
32
+ flags = result['flags']
33
+ syllables = result['syllables']
34
+ print Rainbow('Word|').bright
35
+ print "#{word}"
36
+ print Rainbow('|ARPABET|').bright
37
+ print "#{pron}"
38
+ print Rainbow('|IPA|').bright
39
+ print "#{ipa}"
40
+ print Rainbow('|Syllables|').bright
41
+ print "#{syllables}"
42
+ print Rainbow('|Flags|').bright
43
+ word = { 'word' => word }
44
+ pron = { 'ARPABET pronunciation' => pron }
45
+ ipa = { 'IPA pronunciation' => ipa }
46
+ syllables = { 'syllables' => syllables }
47
+ Lyracyst.tofile(word)
48
+ Lyracyst.tofile(pron)
49
+ Lyracyst.tofile(ipa)
50
+ Lyracyst.tofile(syllables)
51
+ f = Lyracyst::Rhymebrain::Info.new
52
+ f.flag_extra(flags)
53
+ end
54
+ # Extra flag tasks.
55
+ #
56
+ # @param flags [String] ABC flags to process.
57
+ def flag_extra(flags)
58
+ fcont = []
59
+ if flags =~ /a/
60
+ flag = { 'aflag' => 'The word is offensive.' }
61
+ fcont.push Rainbow(flag['aflag']).red.bright
62
+ Lyracyst.tofile(flag)
63
+ end
64
+ if flags =~ /b/
65
+ flag = { 'bflag' => 'The word might be found in most dictionaries.' }
66
+ fcont.push flag['bflag']
67
+ Lyracyst.tofile(flag)
68
+ end
69
+ if flags =~ /c/
70
+ flag = { 'cflag' => 'The pronunciation is known with confidence. It was not automatically generated.' }
71
+ fcont.push flag['cflag']
72
+ Lyracyst.tofile(flag)
60
73
  end
74
+ puts "#{fcont.join(Rainbow('|').bright)}"
61
75
  end
62
76
  end
63
77
  end
@@ -13,23 +13,29 @@ module Lyracyst
13
13
  result = rh.get_word(search, func, params, result)
14
14
  result = MultiJson.load(result)
15
15
  if result != nil
16
- a, b, rcont = 0, result.length - 1, []
16
+ Lyracyst.label(label)
17
17
  type = { 'type' => 'rhyme' }
18
18
  st = { 'searchterm' => search }
19
19
  Lyracyst.tofile(st)
20
20
  Lyracyst.tofile(type)
21
- while a <= b
22
- match = result[a]
23
- rhyme = match['word']
24
- rcont.push rhyme
25
- rhyme = { 'rhyme' => rhyme }
26
- Lyracyst.tofile(rhyme)
27
- a += 1
28
- end
29
- Lyracyst.label(label)
30
- print rcont.join(Rainbow('|').bright)
31
- puts ''
21
+ e = Lyracyst::Rhymebrain::Rhyme.new
22
+ e.rhyme_extra(result)
23
+ end
24
+ end
25
+ # Extra repetitive tasks.
26
+ #
27
+ # @param result [Array] List of hashes to process.
28
+ def rhyme_extra(result)
29
+ a, b, rcont = 0, result.length - 1, []
30
+ while a <= b
31
+ match = result[a]
32
+ rhyme = match['word']
33
+ rcont.push rhyme
34
+ rhyme = { 'rhyme' => rhyme }
35
+ Lyracyst.tofile(rhyme)
36
+ a += 1
32
37
  end
38
+ puts rcont.join(Rainbow('|').bright)
33
39
  end
34
40
  end
35
41
  end
@@ -26,7 +26,6 @@ module Lyracyst
26
26
  list = result['list']
27
27
  Lyracyst.label(label)
28
28
  print Rainbow("|Tags|#{tags}|Type|#{rtype}").bright
29
- x, y, dcont = 0, list.length - 1, []
30
29
  st = { 'searchterm' => search }
31
30
  Lyracyst.tofile(st)
32
31
  type = { 'type' => 'urban' }
@@ -35,6 +34,14 @@ module Lyracyst
35
34
  Lyracyst.tofile(type)
36
35
  Lyracyst.tofile(tags)
37
36
  Lyracyst.tofile(rtype)
37
+ e = Lyracyst::Urban::Define.new
38
+ e.urban_extra(list)
39
+ end
40
+ # Extra reptitive tasks.
41
+ #
42
+ # @param list [Array] List of hashes to process.
43
+ def urban_extra(list)
44
+ x, y = 0, list.length - 1
38
45
  while x <= y
39
46
  obj = list[x]
40
47
  author = obj['author']
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
  module Lyracyst
3
3
  # Semantic program version
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
@@ -16,34 +16,41 @@ module Lyracyst
16
16
  # @param part [String] Comma-separated list of parts of speech.
17
17
  # @param params [Hash] The search parameters to use.
18
18
  def get_def(search, part, params)
19
- func, label, result = 'definitions', 'Definition', nil
19
+ func, result = 'definitions', nil
20
20
  if part != nil then params[:part] = part; end
21
21
  defi = Lyracyst::Wordnik.new
22
22
  result = defi.get_word(search, func, params, result)
23
23
  result = MultiJson.load(result)
24
24
  if result != nil
25
- x, y = 0, result.length - 1
26
25
  st = { 'searchterm' => search }
27
26
  type = { 'type' => 'definition' }
28
27
  Lyracyst.tofile(st)
29
28
  Lyracyst.tofile(type)
30
- while x <= y
31
- d = result[x]
32
- text = d['text']
33
- part = d['partOfSpeech']
34
- Lyracyst.label(label)
35
- print Rainbow("#{part}|").bright
36
- puts "#{text}|"
37
- part = { 'part' => part }
38
- text = { 'text' => text }
39
- Lyracyst.tofile(part)
40
- Lyracyst.tofile(text)
41
- x += 1
42
- end
29
+ e = Lyracyst::Wordnik::Define.new
30
+ e.define_extra(result)
43
31
  else
44
32
  puts 'Wordnik returned an empty string.'
45
33
  end
46
34
  end
35
+ # Extra repetitive tasks.
36
+ #
37
+ # @param result [Array] List of hashes to process.
38
+ def define_extra(result)
39
+ x, y, label = 0, result.length - 1, 'Definition'
40
+ while x <= y
41
+ d = result[x]
42
+ text = d['text']
43
+ part = d['partOfSpeech']
44
+ Lyracyst.label(label)
45
+ print Rainbow("#{part}|").bright
46
+ puts "#{text}|"
47
+ part = { 'part' => part }
48
+ text = { 'text' => text }
49
+ Lyracyst.tofile(part)
50
+ Lyracyst.tofile(text)
51
+ x += 1
52
+ end
53
+ end
47
54
  end
48
55
  end
49
56
  end
@@ -8,37 +8,44 @@ module Lyracyst
8
8
  # @param search [String] The word or phrase to search for.
9
9
  # @param params [Hash] The search parameters to use.
10
10
  def get_ex(search, params)
11
- func, label, result = 'examples', 'Example', nil
11
+ func, result = 'examples', nil
12
12
  exam = Lyracyst::Wordnik.new
13
13
  result = exam.get_word(search, func, params, result)
14
14
  result = MultiJson.load(result)
15
15
  result = result['examples']
16
16
  if result != nil
17
- x, y = 0, result.length - 1
18
17
  st = { 'searchterm' => search }
19
18
  ty = { 'type' => 'example' }
20
19
  Lyracyst.tofile(st)
21
20
  Lyracyst.tofile(ty)
22
- while x <= y
23
- ex = result[x]
24
- title = ex['title']
25
- text = ex['text']
26
- url = ex['url']
27
- Lyracyst.label(label)
28
- print Rainbow("#{title}|").bright
29
- puts "#{text}|#{url}|"
30
- ti = { 'title' => title }
31
- te = { 'text' => text }
32
- u = { 'url' => url }
33
- Lyracyst.tofile(ti)
34
- Lyracyst.tofile(te)
35
- Lyracyst.tofile(u)
36
- x += 1
37
- end
21
+ e = Lyracyst::Wordnik::Example.new
22
+ e.ex_extra(result)
38
23
  else
39
24
  puts 'Wordnik failed to fetch word info.'
40
25
  end
41
26
  end
27
+ # Extra repetitive tasks.
28
+ #
29
+ # @param result [Array] List of hashes to process.
30
+ def ex_extra(result)
31
+ x, y, label = 0, result.length - 1, 'Example'
32
+ while x <= y
33
+ ex = result[x]
34
+ title = ex['title']
35
+ text = ex['text']
36
+ url = ex['url']
37
+ Lyracyst.label(label)
38
+ print Rainbow("#{title}|").bright
39
+ puts "#{text}|#{url}|"
40
+ ti = { 'title' => title }
41
+ te = { 'text' => text }
42
+ u = { 'url' => url }
43
+ Lyracyst.tofile(ti)
44
+ Lyracyst.tofile(te)
45
+ Lyracyst.tofile(u)
46
+ x += 1
47
+ end
48
+ end
42
49
  end
43
50
  end
44
51
  end
@@ -13,39 +13,46 @@ module Lyracyst
13
13
  result = hyph.get_word(search, func, params, result)
14
14
  result = MultiJson.load(result)
15
15
  if result != nil
16
- x, y, hcont = 0, result.length - 1, []
17
16
  Lyracyst.label(label)
18
17
  t = { 'type' => 'hyphenation' }
19
18
  st = { 'searchterm' => search }
20
19
  Lyracyst.tofile(st)
21
20
  Lyracyst.tofile(t)
22
- while x <= y
23
- hy = result[x]
24
- ht = hy['text']
25
- if hy['type'] == 'stress'
26
- stress = 'primary'
27
- sh = { ht => stress }
28
- h = { 'syllable' => sh }
29
- Lyracyst.tofile(h)
30
- hcont.push Rainbow(ht).red.bright
31
- elsif hy['type'] == 'secondary stress'
32
- stress = 'secondary'
33
- sh = { ht => stress }
34
- h = { 'syllable' => sh }
35
- Lyracyst.tofile(h)
36
- hcont.push Rainbow(ht).bright
37
- else
38
- h = { 'syllable' => ht }
39
- Lyracyst.tofile(h)
40
- hcont.push ht
41
- end
42
- x += 1
43
- end
44
- puts hcont.join('-')
21
+ e = Lyracyst::Wordnik::Hyphen.new
22
+ e.hyphen_extra(result)
45
23
  else
46
24
  puts 'Wordnik failed to fetch word info.'
47
25
  end
48
26
  end
27
+ # Extra repetitive tasks.
28
+ #
29
+ # @param result [Array] List of hashes to process.
30
+ def hyphen_extra(result)
31
+ x, y, hcont = 0, result.length - 1, []
32
+ while x <= y
33
+ hy = result[x]
34
+ ht = hy['text']
35
+ if hy['type'] == 'stress'
36
+ stress = 'primary'
37
+ sh = { ht => stress }
38
+ h = { 'syllable' => sh }
39
+ Lyracyst.tofile(h)
40
+ hcont.push Rainbow(ht).red.bright
41
+ elsif hy['type'] == 'secondary stress'
42
+ stress = 'secondary'
43
+ sh = { ht => stress }
44
+ h = { 'syllable' => sh }
45
+ Lyracyst.tofile(h)
46
+ hcont.push Rainbow(ht).bright
47
+ else
48
+ h = { 'syllable' => ht }
49
+ Lyracyst.tofile(h)
50
+ hcont.push ht
51
+ end
52
+ x += 1
53
+ end
54
+ puts hcont.join('-')
55
+ end
49
56
  end
50
57
  end
51
58
  end
@@ -8,48 +8,55 @@ module Lyracyst
8
8
  # @param search [String] The word or phrase to search for.
9
9
  # @param params [Hash] The search parameters to use.
10
10
  def get_et(search, params)
11
- func, label, result = 'etymologies', 'Etymology', nil
11
+ func, result = 'etymologies', nil
12
12
  etymology = Lyracyst::Wordnik.new
13
- extra = Lyracyst::Wordnik::Origin.new
13
+ e = Lyracyst::Wordnik::Origin.new
14
14
  result = etymology.get_word(search, func, params, result)
15
15
  if result != nil && result != '[]'
16
16
  result = MultiJson.load(result)
17
- a, b, cont = 0, result.length - 1, []
18
17
  type = { 'type' => 'etymology' }
19
18
  st = { 'searchterm' => search }
20
19
  Lyracyst.tofile(st)
21
20
  Lyracyst.tofile(type)
22
- while a <= b
23
- xml = result[a]
24
- xml = MultiXml.parse(xml)
25
- root = xml['ety']
26
- content, ets, er = root['__content__'], root['ets'], root['er']
27
- root = { 'root' => content }
28
- Lyracyst.tofile(root)
29
- Lyracyst.label(label)
30
- print "#{content}|"
31
- if ets != nil
32
- extra.origin_extra(ets)
33
- else
34
- puts ''
35
- end
36
- if er != nil
37
- print '|'
38
- extra.origin_extra(er)
39
- else
40
- puts ''
41
- end
42
- a += 1
43
- puts ''
44
- end
21
+ e.origin_extra(result)
45
22
  else
46
23
  puts 'Wordnik failed to fetch word info.'
47
24
  end
48
25
  end
49
- # Extra reptetive tasks
26
+ # Extra repetitive tasks.
27
+ #
28
+ # @param result [Array] List of hashes to process.
29
+ def origin_extra(result)
30
+ ee = Lyracyst::Wordnik::Origin.new
31
+ a, b, label = 0, result.length - 1, 'Etymology'
32
+ while a <= b
33
+ xml = result[a]
34
+ xml = MultiXml.parse(xml)
35
+ root = xml['ety']
36
+ content, ets, er = root['__content__'], root['ets'], root['er']
37
+ root = { 'root' => content }
38
+ Lyracyst.tofile(root)
39
+ Lyracyst.label(label)
40
+ print "#{content}|"
41
+ if ets != nil
42
+ ee.origin_extra2(ets)
43
+ else
44
+ puts ''
45
+ end
46
+ if er != nil
47
+ print '|'
48
+ ee.origin_extra2(er)
49
+ else
50
+ puts ''
51
+ end
52
+ a += 1
53
+ puts ''
54
+ end
55
+ end
56
+ # Extra repetitive tasks.
50
57
  #
51
- # @param obj [Hash] Object hash to process
52
- def origin_extra(obj)
58
+ # @param obj [Hash] Object hash to process.
59
+ def origin_extra2(obj)
53
60
  a, b, container = 0, obj.length - 1, []
54
61
  while a <= b
55
62
  if b == 0
@@ -13,33 +13,41 @@ module Lyracyst
13
13
  result = phr.get_word(search, func, params, result)
14
14
  result = MultiJson.load(result)
15
15
  if result != nil
16
- x, y, phcont = 0, result.length - 1, []
17
16
  Lyracyst.label(label)
18
17
  type = { 'type' => 'phrase' }
19
18
  st = { 'searchterm' => search }
20
19
  Lyracyst.tofile(st)
21
20
  Lyracyst.tofile(type)
22
- while x <= y
23
- ph = result[x]
24
- one = ph['gram1']
25
- two = ph['gram2']
26
- g1 = { 'gram1' => one }
27
- g2 = { 'gram2' => two }
28
- Lyracyst.tofile(g1)
29
- Lyracyst.tofile(g2)
30
- if one == search
31
- item = "#{Rainbow(one).bright}➜#{two}"
32
- else
33
- item = "#{one}➜#{Rainbow(two).bright}"
34
- end
35
- phcont.push item
36
- x += 1
37
- end
38
- puts "#{phcont.join('➜')}"
21
+ e = Lyracyst::Wordnik::Phrase.new
22
+ e.phrase_extra(search, result)
39
23
  else
40
24
  puts 'Wordnik failed to fetch word info.'
41
25
  end
42
26
  end
27
+ # Extra repetitive tasks.
28
+ #
29
+ # @param search [String] The word or phrase to search for.
30
+ # @param result [Array] List of hashes to process.
31
+ def phrase_extra(search, result)
32
+ x, y, phcont = 0, result.length - 1, []
33
+ while x <= y
34
+ ph = result[x]
35
+ one = ph['gram1']
36
+ two = ph['gram2']
37
+ g1 = { 'gram1' => one }
38
+ g2 = { 'gram2' => two }
39
+ Lyracyst.tofile(g1)
40
+ Lyracyst.tofile(g2)
41
+ if one == search
42
+ item = "#{Rainbow(one).bright}➜#{two}"
43
+ else
44
+ item = "#{one}➜#{Rainbow(two).bright}"
45
+ end
46
+ phcont.push item
47
+ x += 1
48
+ end
49
+ puts "#{phcont.join('➜')}"
50
+ end
43
51
  end
44
52
  end
45
53
  end
@@ -10,33 +10,40 @@ module Lyracyst
10
10
  # @param params [Hash] The search parameters to use.
11
11
  # @param ptype [String] Pronunciation type.
12
12
  def get_pro(search, params, ptype)
13
- func, label, result = 'pronunciations', 'Pronunciation', nil
13
+ func, result = 'pronunciations', nil
14
14
  if ptype != nil then params[:tformat] = ptype; end
15
15
  pron = Lyracyst::Wordnik.new
16
16
  result = pron.get_word(search, func, params, result)
17
17
  result = MultiJson.load(result)
18
18
  if result != nil
19
- x, y = 0, result.length - 1
20
19
  type = { 'type' => 'pronunciation' }
21
20
  st = { 'searchterm' => search }
22
21
  Lyracyst.tofile(st)
23
22
  Lyracyst.tofile(type)
24
- while x <= y
25
- pro = result[x]
26
- rawtype = pro['rawType']
27
- raw = pro['raw']
28
- Lyracyst.label(label)
29
- puts "#{raw}|#{rawtype}|"
30
- pronunciation = { 'pronunciation' => raw }
31
- ptype = { 'ptype' => rawtype }
32
- Lyracyst.tofile(pronunciation)
33
- Lyracyst.tofile(ptype)
34
- x += 1
35
- end
23
+ e = Lyracyst::Wordnik::Pronounce.new
24
+ e.pro_extra(result)
36
25
  else
37
26
  puts 'Wordnik failed to fetch word info.'
38
27
  end
39
28
  end
29
+ # Extra repetitive tasks.
30
+ #
31
+ # @param result [Array] List of hashes to process.
32
+ def pro_extra(result)
33
+ x, y, label = 0, result.length - 1, 'Pronunciation'
34
+ while x <= y
35
+ pro = result[x]
36
+ rawtype = pro['rawType']
37
+ raw = pro['raw']
38
+ Lyracyst.label(label)
39
+ puts "#{raw}|#{rawtype}|"
40
+ pronunciation = { 'pronunciation' => raw }
41
+ ptype = { 'ptype' => rawtype }
42
+ Lyracyst.tofile(pronunciation)
43
+ Lyracyst.tofile(ptype)
44
+ x += 1
45
+ end
46
+ end
40
47
  end
41
48
  end
42
49
  end
@@ -13,33 +13,40 @@ module Lyracyst
13
13
  # @param params [Hash] The search parameters to use.
14
14
  # @param reltypes [String] Relationship type.
15
15
  def get_rel(search, params, reltypes)
16
- func, label, result = 'relatedWords', 'Related words', nil
16
+ func, result = 'relatedWords', nil
17
17
  if reltypes != nil then params[:reltypes] = reltypes; end
18
18
  rel = Lyracyst::Wordnik.new
19
19
  result = rel.get_word(search, func, params, result)
20
20
  result = MultiJson.load(result)
21
21
  if result != nil
22
- x, y = 0, result.length - 1
23
22
  type = { 'type' => 'related words' }
24
23
  st = { 'searchterm' => search }
25
24
  Lyracyst.tofile(st)
26
25
  Lyracyst.tofile(type)
27
- while x <= y
28
- re = result[x]
29
- words, type = re['words'], re['relationshipType']
30
- Lyracyst.label(label)
31
- print Rainbow("#{type}|").bright
32
- puts "#{words.join('|')}"
33
- words = { 'words' => words }
34
- rtype = { 'relationship type' => type }
35
- Lyracyst.tofile(words)
36
- Lyracyst.tofile(rtype)
37
- x += 1
38
- end
26
+ e = Lyracyst::Wordnik::Relate.new
27
+ e.rel_extra(result)
39
28
  else
40
29
  puts 'Wordnik failed to fetch word info.'
41
30
  end
42
31
  end
32
+ # Extra repetitive tasks.
33
+ #
34
+ # @param result [Array] List of hashes to process.
35
+ def rel_extra(result)
36
+ x, y, label = 0, result.length - 1, 'Related words'
37
+ while x <= y
38
+ re = result[x]
39
+ words, type = re['words'], re['relationshipType']
40
+ Lyracyst.label(label)
41
+ print Rainbow("#{type}|").bright
42
+ puts "#{words.join('|')}"
43
+ words = { 'words' => words }
44
+ rtype = { 'relationship type' => type }
45
+ Lyracyst.tofile(words)
46
+ Lyracyst.tofile(rtype)
47
+ x += 1
48
+ end
49
+ end
43
50
  end
44
51
  end
45
52
  end
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.1
4
+ version: 1.0.2
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-10 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli