lyracyst 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lyracyst +6 -4
- data/lib/lyracyst.rb +6 -4
- data/lib/lyracyst/cli/wordsmith.rb +37 -0
- data/lib/lyracyst/version.rb +1 -1
- data/lib/lyracyst/wordsmith.rb +46 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a780a45175c797ef44cbc04717e89162e8697f8f
|
4
|
+
data.tar.gz: 0cd971d9e94edb8ac182acfe62b5339e25324653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7942def2999a3f072c5b3d02f952904c338114813c2f153a5089975d919203226decfaf3a4f6f105cd13d9a907792bbd1ac2c4a7fb74d87e1452734a4a2fcd4a
|
7
|
+
data.tar.gz: 3f84b9ce326a6cf603c59a2f6ca8ca2d7c4739287dc6dc0659e3f075340fe353c4005391bb69138ac184d842d1f5ac64da8ed2ae57d7eb3804580e93aba2799a
|
data/bin/lyracyst
CHANGED
@@ -10,6 +10,7 @@ require 'lyracyst/rhymebrain'
|
|
10
10
|
require 'lyracyst/urban'
|
11
11
|
require 'lyracyst/version'
|
12
12
|
require 'lyracyst/wordnik'
|
13
|
+
require 'lyracyst/wordsmith'
|
13
14
|
require 'xml-fu'
|
14
15
|
|
15
16
|
# The Lyracyst module handles base functionality.
|
@@ -76,6 +77,7 @@ require 'lyracyst/cli/onelook'
|
|
76
77
|
require 'lyracyst/cli/rhymebrain'
|
77
78
|
require 'lyracyst/cli/urban'
|
78
79
|
require 'lyracyst/cli/wordnik'
|
80
|
+
require 'lyracyst/cli/wordsmith'
|
79
81
|
|
80
82
|
pre do |global, command, options, args|
|
81
83
|
# Pre logic here
|
@@ -132,12 +134,12 @@ post do |global, command, options, args|
|
|
132
134
|
outfile = global[:o]
|
133
135
|
if File.exist?(outfile) && global[:fo] == true
|
134
136
|
if $fmt == :json
|
135
|
-
fo = File.
|
137
|
+
fo = File.new(outfile, 'w+')
|
136
138
|
fo.print MultiJson.dump($tofile, :pretty => true)
|
137
139
|
fo.close
|
138
140
|
puts Rainbow("Word search was written to #{outfile}.").bright
|
139
141
|
elsif $fmt == :xml
|
140
|
-
fo = File.
|
142
|
+
fo = File.new(outfile, 'w+')
|
141
143
|
fo.print '<?xml version="1.0" encoding="utf-8"?>'
|
142
144
|
fo.print XmlFu.xml($tofile)
|
143
145
|
fo.close
|
@@ -151,12 +153,12 @@ post do |global, command, options, args|
|
|
151
153
|
ans = gets
|
152
154
|
if ans =~ /y/
|
153
155
|
if $fmt == :json
|
154
|
-
fo = File.
|
156
|
+
fo = File.new(outfile, 'w+')
|
155
157
|
fo.print MultiJson.dump($tofile, :pretty => true)
|
156
158
|
fo.close
|
157
159
|
puts Rainbow("Word search was written to #{outfile}.").bright
|
158
160
|
elsif $fmt == :xml
|
159
|
-
fo = File.
|
161
|
+
fo = File.new(outfile, 'w+')
|
160
162
|
fo.print '<?xml version="1.0" encoding="utf-8"?>'
|
161
163
|
fo.print XmlFu.xml($tofile)
|
162
164
|
fo.close
|
data/lib/lyracyst.rb
CHANGED
@@ -10,6 +10,7 @@ require 'lyracyst/rhymebrain'
|
|
10
10
|
require 'lyracyst/urban'
|
11
11
|
require 'lyracyst/version'
|
12
12
|
require 'lyracyst/wordnik'
|
13
|
+
require 'lyracyst/wordsmith'
|
13
14
|
require 'xml-fu'
|
14
15
|
|
15
16
|
# The Lyracyst module handles base functionality.
|
@@ -76,6 +77,7 @@ require 'lyracyst/cli/onelook'
|
|
76
77
|
require 'lyracyst/cli/rhymebrain'
|
77
78
|
require 'lyracyst/cli/urban'
|
78
79
|
require 'lyracyst/cli/wordnik'
|
80
|
+
require 'lyracyst/cli/wordsmith'
|
79
81
|
|
80
82
|
pre do |global, command, options, args|
|
81
83
|
# Pre logic here
|
@@ -132,12 +134,12 @@ post do |global, command, options, args|
|
|
132
134
|
outfile = global[:o]
|
133
135
|
if File.exist?(outfile) && global[:fo] == true
|
134
136
|
if $fmt == :json
|
135
|
-
fo = File.
|
137
|
+
fo = File.new(outfile, 'w+')
|
136
138
|
fo.print MultiJson.dump($tofile, :pretty => true)
|
137
139
|
fo.close
|
138
140
|
puts Rainbow("Word search was written to #{outfile}.").bright
|
139
141
|
elsif $fmt == :xml
|
140
|
-
fo = File.
|
142
|
+
fo = File.new(outfile, 'w+')
|
141
143
|
fo.print '<?xml version="1.0" encoding="utf-8"?>'
|
142
144
|
fo.print XmlFu.xml($tofile)
|
143
145
|
fo.close
|
@@ -151,12 +153,12 @@ post do |global, command, options, args|
|
|
151
153
|
ans = gets
|
152
154
|
if ans =~ /y/
|
153
155
|
if $fmt == :json
|
154
|
-
fo = File.
|
156
|
+
fo = File.new(outfile, 'w+')
|
155
157
|
fo.print MultiJson.dump($tofile, :pretty => true)
|
156
158
|
fo.close
|
157
159
|
puts Rainbow("Word search was written to #{outfile}.").bright
|
158
160
|
elsif $fmt == :xml
|
159
|
-
fo = File.
|
161
|
+
fo = File.new(outfile, 'w+')
|
160
162
|
fo.print '<?xml version="1.0" encoding="utf-8"?>'
|
161
163
|
fo.print XmlFu.xml($tofile)
|
162
164
|
fo.close
|
@@ -0,0 +1,37 @@
|
|
1
|
+
desc 'Fetches anagrams from Wordsmith'
|
2
|
+
arg_name 'word'
|
3
|
+
command :ana do |c|
|
4
|
+
c.flag :lang, :default_value => 'english', :arg_name => 'string', :desc => 'english,english-obscure,german,spanish,esperanto,french,italian,latin,dutch,portuguese,swedish,names'
|
5
|
+
c.flag :limit, :default_value => 10, :arg_name => 'integer', :desc => 'Limits number of results returned'
|
6
|
+
c.flag :maxwords, :default_value => nil, :arg_name => 'integer', :desc => 'Maximum number of words in each anagram'
|
7
|
+
c.flag :include, :default_value => nil, :arg_name => 'string', :desc => 'Anagrams must include this word'
|
8
|
+
c.flag :exclude, :default_value => nil, :arg_name => 'string', :desc => 'Anagrams must exclude these words'
|
9
|
+
c.flag :minletters, :default_value => nil, :arg_name => 'integer', :desc => 'Minimum number of letters in each word'
|
10
|
+
c.flag :maxletters, :default_value => nil, :arg_name => 'integer', :desc => 'Maximum number of letters in each word'
|
11
|
+
c.flag :case, :default_value => 1, :arg_name => 'integer', :desc => '0 - Lowercase, 1 - First Letter, 2 - Uppercase'
|
12
|
+
c.switch :repeat, :default_value => false, :desc => 'Repeat occurrences of a word OK'
|
13
|
+
c.switch :list, :default_value => false, :desc => 'Show candidate word list only'
|
14
|
+
c.switch :linenum, :default_value => false, :desc => 'Show line numbers with anagrams'
|
15
|
+
c.action do |global_options, options, args|
|
16
|
+
search = args[0]
|
17
|
+
if options[:repeat] == true
|
18
|
+
repeat = 'y'
|
19
|
+
else
|
20
|
+
repeat = 'n'
|
21
|
+
end
|
22
|
+
if options[:list] == true
|
23
|
+
list = 'y'
|
24
|
+
else
|
25
|
+
list = 'n'
|
26
|
+
end
|
27
|
+
if options[:linenum] == true
|
28
|
+
linenum = 'y'
|
29
|
+
else
|
30
|
+
linenum = 'n'
|
31
|
+
end
|
32
|
+
params = { lang: options[:lang], limit: options[:limit], maxwords: options[:maxwords], include: options[:include], exclude: options[:exclude], minletters: options[:minletters], maxletters: options[:maxletters], case: options[:case], repeat: repeat, list: list, linenum: linenum }
|
33
|
+
result = nil
|
34
|
+
ana = Lyracyst::Wordsmith.new
|
35
|
+
ana.scrape(search, params, result)
|
36
|
+
end
|
37
|
+
end
|
data/lib/lyracyst/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'metainspector'
|
3
|
+
|
4
|
+
module Lyracyst
|
5
|
+
# Wordsmith.org provides anagrams.
|
6
|
+
class Wordsmith
|
7
|
+
# The scraper method.
|
8
|
+
#
|
9
|
+
# @param search [String] The string of letters to rearrange.
|
10
|
+
# @param params [Hash] The search parameters to use.
|
11
|
+
# @param result [Hash] The search results.
|
12
|
+
def scrape(search, params, result)
|
13
|
+
prefix = 'http://wordsmith.org/anagram/anagram.cgi?anagram='
|
14
|
+
word, pcont = "#{prefix}#{search}", []
|
15
|
+
params.map { |k, v|
|
16
|
+
if k == :lang then pcont.push "&language=#{v}"; end # string
|
17
|
+
if k == :limit then pcont.push "&t=#{v}"; end # integer
|
18
|
+
if k == :maxwords then pcont.push "&d=#{v}"; end # integer
|
19
|
+
if k == :include then pcont.push "&include=#{v}"; end # string
|
20
|
+
if k == :exclude then pcont.push "&exclude=#{v}"; end # string
|
21
|
+
if k == :minletters then pcont.push "&n=#{v}"; end # integer
|
22
|
+
if k == :maxletters then pcont.push "&m=#{v}"; end # integer
|
23
|
+
if k == :repeat then pcont.push "&a=#{v}"; end # y/n
|
24
|
+
if k == :list then pcont.push "&l=#{v}"; end # y/n
|
25
|
+
if k == :linenum then pcont.push "&q=#{v}"; end # y/n
|
26
|
+
if k == :case then pcont.push "&k=#{v}"; end # 0 - lower, 1 - first, 2 - upper
|
27
|
+
}
|
28
|
+
pcont.push "&src=adv"
|
29
|
+
url = "#{word}#{pcont.join}"
|
30
|
+
result = MetaInspector.new(url)
|
31
|
+
pdoc = result.parsed
|
32
|
+
text = pdoc.at_css('p:nth-child(7)').text
|
33
|
+
s = text.scan(/^\s(\d*) found. Displaying ([a-z0-9 ]*):([a-z\s]*)What's/i)
|
34
|
+
s = s[0]
|
35
|
+
found = s[0]
|
36
|
+
display = s[1]
|
37
|
+
astring = s[2]
|
38
|
+
search = { 'search' => search }
|
39
|
+
anagrams = { 'anagrams' => astring }
|
40
|
+
Lyracyst.tofile(search)
|
41
|
+
Lyracyst.tofile(anagrams)
|
42
|
+
Lyracyst.label('Anagrams')
|
43
|
+
puts "Found #{found}. Displaying #{display}:\n#{astring}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
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.
|
4
|
+
version: 1.2.0
|
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-
|
11
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: metainspector
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.2'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: multi_json
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +206,7 @@ files:
|
|
192
206
|
- lib/lyracyst/cli/rhymebrain.rb
|
193
207
|
- lib/lyracyst/cli/urban.rb
|
194
208
|
- lib/lyracyst/cli/wordnik.rb
|
209
|
+
- lib/lyracyst/cli/wordsmith.rb
|
195
210
|
- lib/lyracyst/onelook.rb
|
196
211
|
- lib/lyracyst/rhymebrain.rb
|
197
212
|
- lib/lyracyst/rhymebrain/combine.rb
|
@@ -209,6 +224,7 @@ files:
|
|
209
224
|
- lib/lyracyst/wordnik/pronounce.rb
|
210
225
|
- lib/lyracyst/wordnik/relate.rb
|
211
226
|
- lib/lyracyst/wordnik/word.rb
|
227
|
+
- lib/lyracyst/wordsmith.rb
|
212
228
|
homepage: http://github.com/weirdpercent/lyracyst
|
213
229
|
licenses:
|
214
230
|
- MIT
|