howdy 0.1.0 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -18,16 +18,27 @@ Howdy enables "how" binary in your system. If for example you want to know what
18
18
  2.showing or characterized by awe.
19
19
  3.Slang. very impressive: That new white convertible is totally awesome.
20
20
 
21
- $ how -c dict.pl awesome
21
+ $ how -c
22
+
23
+ 1. dictionary.com - English dictionary
24
+ 2. urbandictionary.com - Slang dictionary
25
+ 3. dict.pl - Polish-English dictionary
26
+ 4. ling.pl - Polish-English dictionary
27
+ Choose [1..4]: 3
28
+ Seach in dict.pl: awesome
22
29
 
23
30
  fantastyczny; zachwycający; niesamowity
24
31
 
25
32
  = Available Dictionaries
26
33
 
27
- * http://urbandictionary.com
28
- * http://dictionary.com
29
- * http://dict.pl
30
- * http://ling.pl
34
+ * http://urbandictionary.com
35
+ * http://dictionary.com
36
+ * http://dict.pl
37
+ * http://ling.pl
38
+
39
+ = Documentation
40
+
41
+ http://howdy.lomnicki.com.pl
31
42
 
32
43
  = Contributors:
33
44
  * Paweł Pacana http://github.com/pawelpacana
data/TODO ADDED
@@ -0,0 +1,4 @@
1
+ * dict.org support
2
+ * wordreference.com support
3
+ * play pronunciation mp3 files (http://howjsay.com)
4
+ * support for coloring output
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.5
data/bin/how CHANGED
@@ -6,40 +6,55 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'howdy')
6
6
 
7
7
  opts = OptionParser.new do |opts|
8
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
- when 'urbandictionary.com': Howdy::Dictionary::UrbanDictionaryCom
17
- else raise Howdy::HowdyError, 'Choose one of available dictionaries'
9
+ opts.banner = "Usage: #{File.basename($0)} [-c|--choose] [-d|--dict INDEX_OR_LABEL] [-l|--list] [-h|--help] WORDS"
10
+
11
+ opts.on("-c", "--choose", "Interactively choose a dictionary") do |c|
12
+ if dict_klass = Howdy::UI.choose_dictionary
13
+ Howdy::Dictionary.set(dict_klass)
14
+ else
15
+ Howdy::UI.error "Dictionary: '#{c}' not found. Choose one of available dictionaries"
16
+ exit 1
17
+ end
18
+ end
19
+
20
+ opts.on("-d", "--dict INDEX_OR_LABEL", "Choose dictionary by index or label (-l lists available) dictionaries") do |d|
21
+ if d.integer?
22
+ index = d.to_i
23
+ unless Howdy::Dictionary.range_available.include?(index)
24
+ Howdy::UI.error "Index must be on of #{Howdy::Dictionary.range_available}"
25
+ exit 1
26
+ end
27
+ Howdy::Dictionary.set( Howdy::Dictionary.available[index-1] )
28
+ else
29
+ if dict_klass = Howdy::Dictionary.find_by_label(c)
30
+ Howdy::Dictionary.set(dict_klass)
31
+ else
32
+ Howdy::UI.error "Dictionary: '#{c}' not found. Choose one of available dictionaries"
33
+ exit 1
34
+ end
18
35
  end
19
- Howdy::Dictionary.set(dict)
20
36
  end
21
37
 
22
38
  opts.on("-l", "--list", "List available dictionaries") do |l|
23
- Howdy::Dictionary.available.each do |dict|
24
- puts " #{dict.dict_label} - #{dict.dict_description}"
25
- end
26
- exit
39
+ Howdy::UI.list_dictionaries
40
+ exit 1
27
41
  end
28
42
 
29
43
  opts.on_tail("-h", "--help", "Show this message") do |h|
30
- puts opts
31
- exit
44
+ Howdy::UI.error opts
45
+ exit 1
32
46
  end
33
47
 
34
48
  end
35
49
  opts.parse!
36
50
 
37
51
  if ARGV.empty?
38
- puts opts
39
- exit
52
+ query = Howdy::UI.prompt("Search in #{Howdy::Dictionary.current.dict_label}")
53
+ else
54
+ query = ARGV.join(' ')
40
55
  end
41
56
 
42
- dict = Howdy::Dictionary.current.new(ARGV.join(' '))
57
+ dict = Howdy::Dictionary.current.new(query.strip)
43
58
  dict.parse
44
59
  dict.print
45
60
 
data/howdy.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{howdy}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.5"
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-02-14}
12
+ s.date = %q{2010-02-16}
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}
@@ -24,16 +24,19 @@ Gem::Specification.new do |s|
24
24
  "LICENSE",
25
25
  "README.rdoc",
26
26
  "Rakefile",
27
+ "TODO",
27
28
  "VERSION",
28
29
  "bin/how",
29
30
  "howdy.gemspec",
30
31
  "lib/howdy.rb",
31
32
  "lib/howdy/base.rb",
33
+ "lib/howdy/core_ext/ruby/string/integer.rb",
32
34
  "lib/howdy/core_ext/ruby/string/underscore.rb",
33
35
  "lib/howdy/dictionaries/dict_pl.rb",
34
36
  "lib/howdy/dictionaries/dictionary_com.rb",
35
37
  "lib/howdy/dictionaries/ling_pl.rb",
36
38
  "lib/howdy/dictionaries/urban_dictionary_com.rb",
39
+ "lib/howdy/ui.rb",
37
40
  "spec/howdy_spec.rb",
38
41
  "spec/spec_helper.rb"
39
42
  ]
data/lib/howdy/base.rb CHANGED
@@ -31,6 +31,16 @@ module Howdy # :nodoc
31
31
  @@available_dictionaries ||= []
32
32
  end
33
33
 
34
+ # Returns range from 1 to total dictionaries count (1..Dictionary.available.size)
35
+ def self.range_available
36
+ (1..available.size)
37
+ end
38
+
39
+ # Find dictionary class by label
40
+ def self.find_by_label(label)
41
+ available.detect { |dict| dict.dict_label == label.to_s }
42
+ end
43
+
34
44
  # Base class for all dictionaries. Inherit from it if you want to implement
35
45
  # your own dictionary.
36
46
  # Example:
@@ -0,0 +1,8 @@
1
+ class String
2
+
3
+ # Returns true if string include digits only
4
+ def integer?
5
+ !!(self =~ /[0-9]+/)
6
+ end
7
+
8
+ end unless String.method_defined?(:integer?)
data/lib/howdy/ui.rb ADDED
@@ -0,0 +1,45 @@
1
+ module Howdy
2
+ # Layer for user interface. In the simplest case it's just standard output.
3
+ class UI
4
+
5
+ class << self
6
+
7
+ # Displays message on defined output (stdout by default)
8
+ def display(message)
9
+ puts message
10
+ end
11
+
12
+ # Displays message on defined output (stderr by default)
13
+ def error(message)
14
+ $stderr.puts message
15
+ end
16
+
17
+ # prints list of available dictionaries
18
+ def list_dictionaries
19
+ Dictionary.available.each_with_index do |dict, idx|
20
+ display " #{idx+1}. #{dict.dict_label} - #{dict.dict_description}"
21
+ end
22
+ end
23
+
24
+ # Display message and wait for user input.
25
+ # Returns captured data
26
+ def prompt(message)
27
+ print "#{message}: "
28
+ gets
29
+ end
30
+
31
+ def choose_dictionary
32
+ list_dictionaries
33
+ range = Dictionary.range_available
34
+ index = prompt("Choose [#{range}]").to_i
35
+ unless range.include?(index)
36
+ error "No such dictionary. Choose one number of [#{range}]"
37
+ exit 1
38
+ end
39
+ Dictionary.available[index-1]
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
data/lib/howdy.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  $: << File.join(File.dirname(__FILE__), 'howdy')
2
2
 
3
3
  require 'core_ext/ruby/string/underscore'
4
+ require 'core_ext/ruby/string/integer'
4
5
  require 'base'
6
+ require 'ui'
5
7
  Dir[File.join(File.dirname(__FILE__), 'howdy', 'dictionaries', '*.rb')].each { |dict| require dict }
6
8
 
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.1.0
4
+ version: 0.1.5
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-02-14 00:00:00 +01:00
12
+ date: 2010-02-16 00:00:00 +01:00
13
13
  default_executable: how
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -47,16 +47,19 @@ files:
47
47
  - LICENSE
48
48
  - README.rdoc
49
49
  - Rakefile
50
+ - TODO
50
51
  - VERSION
51
52
  - bin/how
52
53
  - howdy.gemspec
53
54
  - lib/howdy.rb
54
55
  - lib/howdy/base.rb
56
+ - lib/howdy/core_ext/ruby/string/integer.rb
55
57
  - lib/howdy/core_ext/ruby/string/underscore.rb
56
58
  - lib/howdy/dictionaries/dict_pl.rb
57
59
  - lib/howdy/dictionaries/dictionary_com.rb
58
60
  - lib/howdy/dictionaries/ling_pl.rb
59
61
  - lib/howdy/dictionaries/urban_dictionary_com.rb
62
+ - lib/howdy/ui.rb
60
63
  - spec/howdy_spec.rb
61
64
  - spec/spec_helper.rb
62
65
  has_rdoc: true