howdy 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -3
- data/VERSION +1 -1
- data/howdy.gemspec +9 -5
- data/lib/howdy/base.rb +5 -1
- data/lib/howdy/config.rb +69 -0
- data/lib/howdy/dictionaries/dictionary_com.rb +4 -2
- data/lib/howdy/templates/howdy +1 -0
- data/lib/howdy/ui.rb +2 -1
- data/lib/howdy.rb +1 -0
- metadata +5 -2
data/README.rdoc
CHANGED
@@ -4,7 +4,6 @@ Dead easy command line dictionary.
|
|
4
4
|
|
5
5
|
= Installation
|
6
6
|
|
7
|
-
gem sources -a http://gemcutter.org
|
8
7
|
gem install howdy
|
9
8
|
|
10
9
|
= Description
|
@@ -18,17 +17,29 @@ Howdy enables "how" binary in your system. If for example you want to know what
|
|
18
17
|
2.showing or characterized by awe.
|
19
18
|
3.Slang. very impressive: That new white convertible is totally awesome.
|
20
19
|
|
21
|
-
$ how -c
|
20
|
+
$ how -c awesome
|
22
21
|
|
23
22
|
1. dictionary.com - English dictionary
|
24
23
|
2. urbandictionary.com - Slang dictionary
|
25
24
|
3. dict.pl - Polish-English dictionary
|
26
25
|
4. ling.pl - Polish-English dictionary
|
27
26
|
Choose [1..4]: 3
|
28
|
-
Seach in dict.pl: awesome
|
29
27
|
|
30
28
|
fantastyczny; zachwycający; niesamowity
|
31
29
|
|
30
|
+
= Configuration
|
31
|
+
|
32
|
+
Configuration file is created on first howdy run.
|
33
|
+
It's available in $HOME/.howdy
|
34
|
+
|
35
|
+
Currently it handles only 1 option: default_dictionary
|
36
|
+
Examples:
|
37
|
+
default_dictionary = dictionary.com
|
38
|
+
Or
|
39
|
+
default_dictionary = urbandictionary.com
|
40
|
+
|
41
|
+
Just pass one of available dictionaries listed below.
|
42
|
+
|
32
43
|
= Available Dictionaries
|
33
44
|
|
34
45
|
* http://urbandictionary.com
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/howdy.gemspec
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{howdy}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mlomnicki"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-12}
|
13
13
|
s.default_executable = %q{how}
|
14
14
|
s.description = %q{Howdy is a tool that allows querying web dictionaries from a command line.}
|
15
15
|
s.email = %q{michal.lomnicki@gmail.com}
|
16
16
|
s.executables = ["how"]
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE",
|
19
|
-
"README.rdoc"
|
19
|
+
"README.rdoc",
|
20
|
+
"TODO"
|
20
21
|
]
|
21
22
|
s.files = [
|
22
23
|
".document",
|
@@ -30,12 +31,14 @@ Gem::Specification.new do |s|
|
|
30
31
|
"howdy.gemspec",
|
31
32
|
"lib/howdy.rb",
|
32
33
|
"lib/howdy/base.rb",
|
34
|
+
"lib/howdy/config.rb",
|
33
35
|
"lib/howdy/core_ext/ruby/string/integer.rb",
|
34
36
|
"lib/howdy/core_ext/ruby/string/underscore.rb",
|
35
37
|
"lib/howdy/dictionaries/dict_pl.rb",
|
36
38
|
"lib/howdy/dictionaries/dictionary_com.rb",
|
37
39
|
"lib/howdy/dictionaries/ling_pl.rb",
|
38
40
|
"lib/howdy/dictionaries/urban_dictionary_com.rb",
|
41
|
+
"lib/howdy/templates/howdy",
|
39
42
|
"lib/howdy/ui.rb",
|
40
43
|
"spec/howdy_spec.rb",
|
41
44
|
"spec/spec_helper.rb"
|
@@ -66,3 +69,4 @@ Gem::Specification.new do |s|
|
|
66
69
|
s.add_dependency(%q<rspec>, [">= 0"])
|
67
70
|
end
|
68
71
|
end
|
72
|
+
|
data/lib/howdy/base.rb
CHANGED
@@ -10,6 +10,10 @@ module Howdy # :nodoc
|
|
10
10
|
# Howdy::Dictionary exposes accessors of dictionaries collection.
|
11
11
|
module Dictionary
|
12
12
|
|
13
|
+
def self.config
|
14
|
+
@@config ||= Config.new.parse
|
15
|
+
end
|
16
|
+
|
13
17
|
# Returns current dictionary class
|
14
18
|
def self.current
|
15
19
|
@@dictionary ||= default
|
@@ -23,7 +27,7 @@ module Howdy # :nodoc
|
|
23
27
|
|
24
28
|
# Returns default dictionary
|
25
29
|
def self.default
|
26
|
-
DictionaryCom
|
30
|
+
@@default ||= (find_by_label(config[:default_dictionary]) || DictionaryCom)
|
27
31
|
end
|
28
32
|
|
29
33
|
# Returns array of available dictionaries
|
data/lib/howdy/config.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Howdy
|
4
|
+
|
5
|
+
# Howdy configuration.
|
6
|
+
# Configuration file points to $HOME/.howdy by default
|
7
|
+
class Config < Hash
|
8
|
+
|
9
|
+
attr_reader :file
|
10
|
+
|
11
|
+
# Path of default configuration file
|
12
|
+
# It's copied to user directory if config file doesn't exist.
|
13
|
+
TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates', 'howdy')
|
14
|
+
|
15
|
+
def initialize(file = self.class.config_path)
|
16
|
+
@file = file
|
17
|
+
end
|
18
|
+
|
19
|
+
# Parse file and associate options to self
|
20
|
+
# example:
|
21
|
+
# howdy.conf:
|
22
|
+
# default_dictionary = dictionary.com
|
23
|
+
# verbose = true
|
24
|
+
#
|
25
|
+
# c = Config.new('howdy.conf')
|
26
|
+
# c.parse
|
27
|
+
# c.inspect
|
28
|
+
# { :default_dictionary => 'dictionary.com', :verbose => 'true' }
|
29
|
+
def parse
|
30
|
+
readlines.each do |line|
|
31
|
+
next if line =~ /\s*#/
|
32
|
+
key, value = line.split('=', 2).map! { |arg| arg.strip }
|
33
|
+
self[key.to_sym] = value
|
34
|
+
end
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
# path of configuration file
|
39
|
+
# example: /home/stella/.howdy
|
40
|
+
def self.config_path
|
41
|
+
@config_path ||= File.join(root_config_path, config_filename)
|
42
|
+
end
|
43
|
+
|
44
|
+
# root directory of config file
|
45
|
+
# example: /home/stella
|
46
|
+
def self.root_config_path
|
47
|
+
@root_config_path ||= (ENV['HOME'] || '')
|
48
|
+
end
|
49
|
+
|
50
|
+
# filename of configuration file
|
51
|
+
# example: .howdy
|
52
|
+
def self.config_filename
|
53
|
+
@config_filename ||= ".howdy".freeze
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
def readlines
|
58
|
+
config = File.readable?(@file) ? @file : self.class.create_config!
|
59
|
+
return File.readlines(config)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.create_config!
|
63
|
+
FileUtils.cp(TEMPLATE_PATH, config_path)
|
64
|
+
return config_path
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -9,8 +9,10 @@ module Howdy
|
|
9
9
|
description 'English dictionary'
|
10
10
|
|
11
11
|
def parse
|
12
|
-
document.css('div.KonaBody div.results_content
|
13
|
-
|
12
|
+
document.css('div.KonaBody div.results_content div.luna-Ent div.body div.luna-Ent').each do |row|
|
13
|
+
index = row.search('span.dnindex').children.collect { |e| e.content }.join
|
14
|
+
data = row.search('div.dndata').children.collect { |e| e.content }.join
|
15
|
+
result << index + data
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -0,0 +1 @@
|
|
1
|
+
default_dictionary = dictionary.com
|
data/lib/howdy/ui.rb
CHANGED
@@ -16,6 +16,7 @@ module Howdy
|
|
16
16
|
|
17
17
|
# prints list of available dictionaries
|
18
18
|
def list_dictionaries
|
19
|
+
display "Available dictionaries:"
|
19
20
|
Dictionary.available.each_with_index do |dict, idx|
|
20
21
|
display " #{idx+1}. #{dict.dict_label} - #{dict.dict_description}"
|
21
22
|
end
|
@@ -25,7 +26,7 @@ module Howdy
|
|
25
26
|
# Returns captured data
|
26
27
|
def prompt(message)
|
27
28
|
print "#{message}: "
|
28
|
-
gets
|
29
|
+
$stdin.gets
|
29
30
|
end
|
30
31
|
|
31
32
|
def choose_dictionary
|
data/lib/howdy.rb
CHANGED
@@ -2,6 +2,7 @@ $: << File.join(File.dirname(__FILE__), 'howdy')
|
|
2
2
|
|
3
3
|
require 'core_ext/ruby/string/underscore'
|
4
4
|
require 'core_ext/ruby/string/integer'
|
5
|
+
require 'config'
|
5
6
|
require 'base'
|
6
7
|
require 'ui'
|
7
8
|
Dir[File.join(File.dirname(__FILE__), 'howdy', 'dictionaries', '*.rb')].each { |dict| require dict }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: howdy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mlomnicki
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-12 00:00:00 +01:00
|
13
13
|
default_executable: how
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -41,6 +41,7 @@ extensions: []
|
|
41
41
|
extra_rdoc_files:
|
42
42
|
- LICENSE
|
43
43
|
- README.rdoc
|
44
|
+
- TODO
|
44
45
|
files:
|
45
46
|
- .document
|
46
47
|
- .gitignore
|
@@ -53,12 +54,14 @@ files:
|
|
53
54
|
- howdy.gemspec
|
54
55
|
- lib/howdy.rb
|
55
56
|
- lib/howdy/base.rb
|
57
|
+
- lib/howdy/config.rb
|
56
58
|
- lib/howdy/core_ext/ruby/string/integer.rb
|
57
59
|
- lib/howdy/core_ext/ruby/string/underscore.rb
|
58
60
|
- lib/howdy/dictionaries/dict_pl.rb
|
59
61
|
- lib/howdy/dictionaries/dictionary_com.rb
|
60
62
|
- lib/howdy/dictionaries/ling_pl.rb
|
61
63
|
- lib/howdy/dictionaries/urban_dictionary_com.rb
|
64
|
+
- lib/howdy/templates/howdy
|
62
65
|
- lib/howdy/ui.rb
|
63
66
|
- spec/howdy_spec.rb
|
64
67
|
- spec/spec_helper.rb
|