dict 0.1.8 → 0.1.9

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.
Files changed (2) hide show
  1. data/lib/module_main.rb +28 -35
  2. metadata +1 -1
data/lib/module_main.rb CHANGED
@@ -10,42 +10,32 @@ module Main
10
10
  end
11
11
 
12
12
  def self.parse_parameters
13
- opts = Slop.parse do
14
- banner "Usage: $translate -w word [Options]"
15
- on '-w', :word=, 'after this option is a word to translate'
16
- on '-h', :help=, 'help', :argument => :optional
17
- on '-t', :time=, 'time in seconds, default: 300', :as => :int
18
- on '-d', :dict=, 'wiktionary, dictpl', :argument => :optional
13
+ opts = Slop.parse! do
14
+ banner <<-END
15
+ Usage: dict WORD [OPTIONS]
16
+ Search WORD in dict, an open source dictionary aggregator.
17
+ END
18
+
19
+ on '-h', :help, 'display this help message', :argument => :optional
20
+ on '-t', :time=, 'timeout in seconds, default: 300', :as => :int
21
+ on '-d', :dict=, 'wiktionary|dictpl', :argument => :optional
19
22
  end
20
23
  opts
21
24
  end
22
25
 
23
- def self.get_translations(opts)
24
-
25
- if opts.word?
26
- begin
27
- Timeout::timeout(opts[:time].to_i || 300) do
28
- if opts.dict? && opts[:dict] != nil
29
- Dict.get_single_dictionary_translations(opts[:word],opts[:dict])
30
- else
31
- Dict.get_all_dictionaries_translations(opts[:word])
32
- end
33
- end
34
-
35
- rescue
36
- "Timeout for the query."
37
- end
26
+ def self.get_translations(opts, word)
27
+ Timeout::timeout(opts[:time].to_i || 300) do
28
+ if opts.dict? && opts[:dict] != nil
29
+ Dict.get_single_dictionary_translations(word, opts[:dict])
30
+ else
31
+ Dict.get_all_dictionaries_translations(word)
38
32
  end
39
-
33
+ end
34
+ rescue
35
+ "Timeout for the query."
40
36
  end
41
37
 
42
38
  def self.main(opts)
43
-
44
- if check_parameters? == true
45
- puts "Please enter the word. (-h for help)"
46
- exit
47
- end
48
-
49
39
  begin
50
40
  opts = parse_parameters
51
41
  rescue Slop::MissingArgumentError
@@ -53,13 +43,16 @@ module Main
53
43
  exit
54
44
  end
55
45
 
56
- puts get_translations(opts)
57
-
58
- begin
59
- puts opts if opts.help?
60
- puts Dict.available_services if opts.dict?
61
- rescue
62
- nil
46
+ if opts.help?
47
+ puts opts
48
+ elsif opts.dict? && !opts[:dict]
49
+ puts Dict.available_services
50
+ else
51
+ if check_parameters? == true
52
+ puts "Please enter a word. (-h for help)"
53
+ exit
54
+ end
55
+ puts get_translations(opts, ARGV[0])
63
56
  end
64
57
  end
65
58
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: