Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2737a86
commit e3409ad
Showing
11 changed files
with
134 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Feature: Anagram | ||
In order to use my app to get anagrams | ||
As a developer using Spinach | ||
I run the ana command | ||
|
||
Scenario: Anagram command runs | ||
When I run `lyracyst ana warrenpicketcalender` | ||
Then the output should contain anagrams | ||
And the exit status should be 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Spinach::Features::Anagram < Spinach::FeatureSteps | ||
step 'I run `lyracyst ana warrenpicketcalender`' do | ||
@output = `lyracyst ana warrenpicketcalender` | ||
end | ||
|
||
step 'the output should contain anagrams' do | ||
@output =~ /[\[\]A-Za-z0-9. :|]/ | ||
end | ||
|
||
step 'the exit status should be 0' do | ||
$?.exitstatus == 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
desc 'Fetches anagrams from Wordsmith' | ||
arg_name 'word' | ||
command :ana do |c| | ||
c.flag :lang, :default_value => 'english', :arg_name => 'string', :desc => 'english,english-obscure,german,spanish,esperanto,french,italian,latin,dutch,portuguese,swedish,names' | ||
c.flag :limit, :default_value => 10, :arg_name => 'integer', :desc => 'Limits number of results returned' | ||
c.flag :maxwords, :default_value => nil, :arg_name => 'integer', :desc => 'Maximum number of words in each anagram' | ||
c.flag :include, :default_value => nil, :arg_name => 'string', :desc => 'Anagrams must include this word' | ||
c.flag :exclude, :default_value => nil, :arg_name => 'string', :desc => 'Anagrams must exclude these words' | ||
c.flag :minletters, :default_value => nil, :arg_name => 'integer', :desc => 'Minimum number of letters in each word' | ||
c.flag :maxletters, :default_value => nil, :arg_name => 'integer', :desc => 'Maximum number of letters in each word' | ||
c.flag :case, :default_value => 1, :arg_name => 'integer', :desc => '0 - Lowercase, 1 - First Letter, 2 - Uppercase' | ||
c.switch :repeat, :default_value => false, :desc => 'Repeat occurrences of a word OK' | ||
c.switch :list, :default_value => false, :desc => 'Show candidate word list only' | ||
c.switch :linenum, :default_value => false, :desc => 'Show line numbers with anagrams' | ||
c.action do |global_options, options, args| | ||
search = args[0] | ||
if options[:repeat] == true | ||
repeat = 'y' | ||
else | ||
repeat = 'n' | ||
end | ||
if options[:list] == true | ||
list = 'y' | ||
else | ||
list = 'n' | ||
end | ||
if options[:linenum] == true | ||
linenum = 'y' | ||
else | ||
linenum = 'n' | ||
end | ||
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 } | ||
result = nil | ||
ana = Lyracyst::Wordsmith.new | ||
ana.scrape(search, params, result) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# coding: utf-8 | ||
module Lyracyst | ||
# Semantic program version | ||
VERSION = '1.1.0' | ||
VERSION = '1.2.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# coding: utf-8 | ||
require 'metainspector' | ||
|
||
module Lyracyst | ||
# Wordsmith.org provides anagrams. | ||
class Wordsmith | ||
# The scraper method. | ||
# | ||
# @param search [String] The string of letters to rearrange. | ||
# @param params [Hash] The search parameters to use. | ||
# @param result [Hash] The search results. | ||
def scrape(search, params, result) | ||
prefix = 'http://wordsmith.org/anagram/anagram.cgi?anagram=' | ||
word, pcont = "#{prefix}#{search}", [] | ||
params.map { |k, v| | ||
if k == :lang then pcont.push "&language=#{v}"; end # string | ||
if k == :limit then pcont.push "&t=#{v}"; end # integer | ||
if k == :maxwords then pcont.push "&d=#{v}"; end # integer | ||
if k == :include then pcont.push "&include=#{v}"; end # string | ||
if k == :exclude then pcont.push "&exclude=#{v}"; end # string | ||
if k == :minletters then pcont.push "&n=#{v}"; end # integer | ||
if k == :maxletters then pcont.push "&m=#{v}"; end # integer | ||
if k == :repeat then pcont.push "&a=#{v}"; end # y/n | ||
if k == :list then pcont.push "&l=#{v}"; end # y/n | ||
if k == :linenum then pcont.push "&q=#{v}"; end # y/n | ||
if k == :case then pcont.push "&k=#{v}"; end # 0 - lower, 1 - first, 2 - upper | ||
} | ||
pcont.push "&src=adv" | ||
url = "#{word}#{pcont.join}" | ||
result = MetaInspector.new(url) | ||
pdoc = result.parsed | ||
text = pdoc.at_css('p:nth-child(7)').text | ||
s = text.scan(/^\s(\d*) found. Displaying ([a-z0-9 ]*):([a-z\s]*)What's/i) | ||
s = s[0] | ||
found = s[0] | ||
display = s[1] | ||
astring = s[2] | ||
search = { 'search' => search } | ||
anagrams = { 'anagrams' => astring } | ||
Lyracyst.tofile(search) | ||
Lyracyst.tofile(anagrams) | ||
Lyracyst.label('Anagrams') | ||
puts "Found #{found}. Displaying #{display}:\n#{astring}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters