iciba 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/fy +4 -1
- data/lib/iciba/fanyi.rb +5 -3
- data/lib/iciba/version.rb +1 -1
- metadata +1 -1
data/bin/fy
CHANGED
@@ -10,6 +10,7 @@ OptionParser.new do |opts|
|
|
10
10
|
opts.banner = "Usage: #{File.basename($0)} ('words'|word)"
|
11
11
|
opts.on("-l", "--links", "Download links?") { |b| $links = true }
|
12
12
|
opts.on("-i", "--interactive", "Download links?") { |b| $interactive = true }
|
13
|
+
opts.on("-e", "--extended", "Extended") { |b| $extended = true }
|
13
14
|
opts.on("-h", "--help", "go to fy.iciba.com") do
|
14
15
|
puts opts
|
15
16
|
exit 0
|
@@ -45,5 +46,7 @@ def loop_through_links(links)
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
|
49
|
+
extended = ($extended ? true : false)
|
50
|
+
|
51
|
+
Iciba::Fanyi.new(ARGV.first, 'auto', true, extended)
|
49
52
|
loop_through_links(links) if ($links && links.size > 0)
|
data/lib/iciba/fanyi.rb
CHANGED
@@ -5,12 +5,12 @@ module Iciba
|
|
5
5
|
|
6
6
|
|
7
7
|
|
8
|
-
def initialize(words, dir='auto', bin=false)
|
8
|
+
def initialize(words, dir='auto', bin=false, extended=false)
|
9
9
|
puts '------------------------------------------------------------------------------------' if bin
|
10
10
|
# puts if bingit
|
11
11
|
puts wrap_text(words, 40)
|
12
12
|
puts '------------------------------------------------------------------------------------' if bin
|
13
|
-
download_and_parse(words, dir)
|
13
|
+
download_and_parse(words, dir, extended)
|
14
14
|
puts wrap_text(self.result) if bin
|
15
15
|
puts '------------------------------------------------------------------------------------' if bin
|
16
16
|
return self.result
|
@@ -22,11 +22,13 @@ module Iciba
|
|
22
22
|
end
|
23
23
|
|
24
24
|
|
25
|
-
def download_and_parse(words, dir)
|
25
|
+
def download_and_parse(words, dir, extended)
|
26
26
|
self.response = Iciba::Tools.parse(Iciba::Tools.post('http://fy.iciba.com/api.php', {:q => words, :type => dir}).body_str)
|
27
27
|
self.html = self.response.ret
|
28
28
|
self.result = (Iciba::Tools.doc(self.html)/'span.dd').text.strip
|
29
29
|
self.result = self.html if self.result == ""
|
30
|
+
self.result = self.result.split(',')[0] if self.result.include?(',') unless extended
|
31
|
+
self.result = self.result.split(';')[0] if self.result.include?(';') unless extended
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
data/lib/iciba/version.rb
CHANGED