dict 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/module_main.rb +28 -35
- 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
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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.
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
puts
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
|