howdy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +44 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/bin/how +37 -0
- data/howdy.gemspec +64 -0
- data/lib/howdy/dictionaries/base.rb +80 -0
- data/lib/howdy/dictionaries/dict_pl.rb +25 -0
- data/lib/howdy/dictionaries/dictionary_com.rb +20 -0
- data/lib/howdy/dictionaries/ling_pl.rb +20 -0
- data/lib/howdy/pair.rb +22 -0
- data/lib/howdy.rb +14 -0
- data/spec/howdy_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +91 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Michał Łomnicki
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
= Howdy
|
2
|
+
|
3
|
+
Dead easy command line dictionary.
|
4
|
+
|
5
|
+
= Installation
|
6
|
+
|
7
|
+
gem sources -a http://gemcutter.org
|
8
|
+
gem install howdy
|
9
|
+
|
10
|
+
= Description
|
11
|
+
|
12
|
+
Hodwy is a tool that allowsi you querying web dictionaries from a command line.
|
13
|
+
Howdy enables "how" binary in your system. If for example you want to know what does 'awesome' mean than just issue:
|
14
|
+
|
15
|
+
$ how awesome
|
16
|
+
|
17
|
+
1.inspiring awe: an awesome sight.
|
18
|
+
2.showing or characterized by awe.
|
19
|
+
3.Slang. very impressive: That new white convertible is totally awesome.
|
20
|
+
|
21
|
+
$ how -c dict.pl awesome
|
22
|
+
|
23
|
+
fantastyczny; zachwycający; niesamowity
|
24
|
+
|
25
|
+
= Available Dictionaries
|
26
|
+
|
27
|
+
* http://dictionary.com
|
28
|
+
* http://dict.pl
|
29
|
+
* http://ling.pl
|
30
|
+
|
31
|
+
== Note on Patches/Pull Requests
|
32
|
+
|
33
|
+
* Fork the project.
|
34
|
+
* Make your feature addition or bug fix.
|
35
|
+
* Add tests for it. This is important so I don't break it in a
|
36
|
+
future version unintentionally.
|
37
|
+
* Commit, do not mess with rakefile, version, or history.
|
38
|
+
(if you want to have your own version, that is fine but
|
39
|
+
bump version in a commit by itself I can ignore when I pull)
|
40
|
+
* Send me a pull request. Bonus points for topic branches.
|
41
|
+
|
42
|
+
== Copyright
|
43
|
+
|
44
|
+
Copyright (c) 2010 Michał Łomnicki. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "howdy"
|
8
|
+
gem.summary = %Q{Query web dictionaries from command line}
|
9
|
+
gem.description = %Q{Hodwy is a tool that allowsi you querying web dictionaries from a command line.}
|
10
|
+
gem.email = "michal.lomnicki@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/mlomnicki/howdy"
|
12
|
+
gem.authors = ["mlomnicki"]
|
13
|
+
gem.add_dependency "nokogiri"
|
14
|
+
gem.add_development_dependency "rspec"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
if File.exist?('VERSION')
|
40
|
+
version = File.read('VERSION')
|
41
|
+
else
|
42
|
+
version = ""
|
43
|
+
end
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "howdy #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/how
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'optparse'
|
5
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'howdy')
|
6
|
+
|
7
|
+
opts = OptionParser.new do |opts|
|
8
|
+
|
9
|
+
opts.banner = "Usage: #{$0} [options]"
|
10
|
+
|
11
|
+
opts.on("-c", "--choose DICTIONARY", "Interactively choose dictionary or pass one of: dict.pl, ling.pl") do |c|
|
12
|
+
dict = case c
|
13
|
+
when 'dict.pl': Howdy::Dictionary::DictPl
|
14
|
+
when 'ling.pl': Howdy::Dictionary::LingPl
|
15
|
+
when 'dictionary.com': Howdy::Dictionary::DictionaryCom
|
16
|
+
else raise Howdy::HowdyError, 'Choose one of available dictionaries'
|
17
|
+
end
|
18
|
+
Howdy::Dictionary.set(dict)
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on_tail("-h", "--help", "Show this message") do |h|
|
22
|
+
puts opts
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
opts.parse!
|
28
|
+
|
29
|
+
if ARGV.empty?
|
30
|
+
puts opts
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
dict = Howdy::Dictionary.current.new(ARGV.join(' '))
|
35
|
+
dict.parse
|
36
|
+
dict.print
|
37
|
+
|
data/howdy.gemspec
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{howdy}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["mlomnicki"]
|
12
|
+
s.date = %q{2010-02-14}
|
13
|
+
s.default_executable = %q{how}
|
14
|
+
s.description = %q{Hodwy is a tool that allowsi you querying web dictionaries from a command line.}
|
15
|
+
s.email = %q{michal.lomnicki@gmail.com}
|
16
|
+
s.executables = ["how"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/how",
|
29
|
+
"howdy.gemspec",
|
30
|
+
"lib/howdy.rb",
|
31
|
+
"lib/howdy/dictionaries/base.rb",
|
32
|
+
"lib/howdy/dictionaries/dict_pl.rb",
|
33
|
+
"lib/howdy/dictionaries/dictionary_com.rb",
|
34
|
+
"lib/howdy/dictionaries/ling_pl.rb",
|
35
|
+
"lib/howdy/pair.rb",
|
36
|
+
"spec/howdy_spec.rb",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/mlomnicki/howdy}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.5}
|
43
|
+
s.summary = %q{Query web dictionaries from command line}
|
44
|
+
s.test_files = [
|
45
|
+
"spec/howdy_spec.rb",
|
46
|
+
"spec/spec_helper.rb"
|
47
|
+
]
|
48
|
+
|
49
|
+
if s.respond_to? :specification_version then
|
50
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
51
|
+
s.specification_version = 3
|
52
|
+
|
53
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
54
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module Howdy
|
6
|
+
|
7
|
+
module Dictionary
|
8
|
+
|
9
|
+
def self.current
|
10
|
+
@@dictionary ||= default_dictionary
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.set(dictionary)
|
14
|
+
@@dictionary = dictionary
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.default_dictionary
|
18
|
+
DictPl
|
19
|
+
end
|
20
|
+
|
21
|
+
class Base
|
22
|
+
|
23
|
+
attr_reader :user_query
|
24
|
+
|
25
|
+
def initialize(user_query)
|
26
|
+
@user_query = user_query
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.url(dictionary_url)
|
30
|
+
@url = dictionary_url
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.dict_url
|
34
|
+
@url
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.encoding(enc)
|
38
|
+
@encoding = enc.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.doc_encoding
|
42
|
+
@encoding ||= 'UTF-8'
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse
|
46
|
+
raise Howdy::HowdyError, "Implement parse in your Dictionary::Base subclass"
|
47
|
+
end
|
48
|
+
|
49
|
+
def document
|
50
|
+
@document ||= Nokogiri::HTML(open(URI.escape(interpolated_url)), nil, self.class.doc_encoding)
|
51
|
+
end
|
52
|
+
|
53
|
+
def result
|
54
|
+
@result ||= []
|
55
|
+
end
|
56
|
+
|
57
|
+
def print
|
58
|
+
if result.empty?
|
59
|
+
puts "Nothing found"
|
60
|
+
else
|
61
|
+
result.each do |item|
|
62
|
+
puts item.to_s
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
def interpolated_url
|
69
|
+
@interpolated_url ||= self.class.dict_url.gsub(/#\{[^\}]+\}/) do |interpolation|
|
70
|
+
method = interpolation[2..-2].to_sym # drop leading '#{' and trailing '}'
|
71
|
+
raise Howdy::HowdyError.new("Dictionary has to respond to #{method} in order to use it in query") unless respond_to?(method)
|
72
|
+
send(method)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Howdy
|
2
|
+
|
3
|
+
module Dictionary
|
4
|
+
|
5
|
+
class DictPl < Base
|
6
|
+
|
7
|
+
url 'http://www.dict.pl/dict?word=#{user_query}'
|
8
|
+
|
9
|
+
def parse
|
10
|
+
document.css('table.resTable tr.resRow').each do |row|
|
11
|
+
left, right = row.search('td.resWordCol a')
|
12
|
+
if left.content == user_query
|
13
|
+
result << right.content
|
14
|
+
elsif right.content == user_query
|
15
|
+
result << left.content
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Howdy
|
2
|
+
|
3
|
+
module Dictionary
|
4
|
+
|
5
|
+
class DictionaryCom < Base
|
6
|
+
|
7
|
+
url 'http://dictionary.reference.com/browse/#{user_query}'
|
8
|
+
|
9
|
+
def parse
|
10
|
+
document.css('div.KonaBody div.results_content table.luna-Ent tr').each do |row|
|
11
|
+
result << row.search('td').children.collect { |e| e.content }.join
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Howdy
|
2
|
+
|
3
|
+
module Dictionary
|
4
|
+
|
5
|
+
class LingPl < Base
|
6
|
+
|
7
|
+
url 'http://www2.ling.pl/lingfeed-ps.php?word=#{user_query}&sType=0&chooseLang=1'
|
8
|
+
|
9
|
+
def parse
|
10
|
+
document.css('div.dictdef')[0..2].each do |definiton|
|
11
|
+
result << "\n#{definiton.content}\n\n"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
data/lib/howdy/pair.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Howdy
|
2
|
+
|
3
|
+
class Pair
|
4
|
+
|
5
|
+
attr_accessor :left, :right
|
6
|
+
|
7
|
+
CENTER = 85
|
8
|
+
|
9
|
+
def initialize(left = nil, right = nil)
|
10
|
+
@left = left
|
11
|
+
@right = right
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"#{@left.center(CENTER)} => #{@right.center(CENTER)}"
|
16
|
+
end
|
17
|
+
|
18
|
+
alias :inspect :to_s
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/howdy.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$: << File.join(File.dirname(__FILE__),'howdy')
|
2
|
+
|
3
|
+
require 'pair'
|
4
|
+
require 'dictionaries/base'
|
5
|
+
require 'dictionaries/dict_pl'
|
6
|
+
require 'dictionaries/ling_pl'
|
7
|
+
require 'dictionaries/dictionary_com'
|
8
|
+
|
9
|
+
module Howdy
|
10
|
+
|
11
|
+
class HowdyError < Exception; end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
data/spec/howdy_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: howdy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mlomnicki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-14 00:00:00 +01:00
|
13
|
+
default_executable: how
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: Hodwy is a tool that allowsi you querying web dictionaries from a command line.
|
36
|
+
email: michal.lomnicki@gmail.com
|
37
|
+
executables:
|
38
|
+
- how
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- bin/how
|
52
|
+
- howdy.gemspec
|
53
|
+
- lib/howdy.rb
|
54
|
+
- lib/howdy/dictionaries/base.rb
|
55
|
+
- lib/howdy/dictionaries/dict_pl.rb
|
56
|
+
- lib/howdy/dictionaries/dictionary_com.rb
|
57
|
+
- lib/howdy/dictionaries/ling_pl.rb
|
58
|
+
- lib/howdy/pair.rb
|
59
|
+
- spec/howdy_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
has_rdoc: true
|
62
|
+
homepage: http://github.com/mlomnicki/howdy
|
63
|
+
licenses: []
|
64
|
+
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- --charset=UTF-8
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
81
|
+
version:
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.3.5
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Query web dictionaries from command line
|
89
|
+
test_files:
|
90
|
+
- spec/howdy_spec.rb
|
91
|
+
- spec/spec_helper.rb
|