iciba 0.0.4 → 0.0.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/bin/fy +4 -2
- data/lib/iciba.rb +5 -0
- data/lib/iciba/fanyi.rb +6 -1
- data/lib/iciba/version.rb +1 -1
- metadata +1 -1
data/bin/fy
CHANGED
@@ -25,7 +25,6 @@ OptionParser.new do |opts|
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
28
|
def wrap_text(txt, col = 80)
|
30
29
|
txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,
|
31
30
|
"\\1\\3\n")
|
@@ -33,6 +32,9 @@ end
|
|
33
32
|
|
34
33
|
if ARGV.empty?
|
35
34
|
abort "Enter some words to lookup!"
|
35
|
+
elsif ARGV.first == 'open'
|
36
|
+
`open http://fy.iciba.com`
|
37
|
+
abort "opening http://fy.iciba.com"
|
36
38
|
end
|
37
39
|
|
38
40
|
regex = /https?:\/\/[\S]+/
|
@@ -41,7 +43,7 @@ links = ARGV.first.scan(regex)
|
|
41
43
|
def loop_through_links(links)
|
42
44
|
puts links.inspect
|
43
45
|
links.each do |l|
|
44
|
-
text = Readability::Document.new(Iciba::Tools.download(l).force_encoding("UTF-8")).content.gsub('<p>', '').gsub('</p>', "\r\n").gsub('</div
|
46
|
+
text = Readability::Document.new(Iciba::Tools.download(l).force_encoding("UTF-8")).content.gsub('<p>', '').gsub('</p>', "\r\n").gsub('</div>', '').gsub('<div>', '')
|
45
47
|
puts wrap_text(text) unless text == ''
|
46
48
|
puts '------------------------------------------------------------------------------------' unless text == ''
|
47
49
|
end
|
data/lib/iciba.rb
CHANGED
data/lib/iciba/fanyi.rb
CHANGED
@@ -8,7 +8,8 @@ module Iciba
|
|
8
8
|
def initialize(words, dir='auto', bin=false, extended=false)
|
9
9
|
puts '------------------------------------------------------------------------------------' if bin
|
10
10
|
# puts if bingit
|
11
|
-
puts wrap_text(words, 40)
|
11
|
+
puts wrap_text(words, 40) if check_char(words) if bin
|
12
|
+
puts wrap_text(words) unless check_char(words) if bin
|
12
13
|
puts '------------------------------------------------------------------------------------' if bin
|
13
14
|
download_and_parse(words, dir, extended)
|
14
15
|
puts wrap_text(self.result) if bin
|
@@ -20,6 +21,10 @@ module Iciba
|
|
20
21
|
txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,
|
21
22
|
"\\1\\3\n")
|
22
23
|
end
|
24
|
+
|
25
|
+
def check_char(str)
|
26
|
+
str.contains_cjk?
|
27
|
+
end
|
23
28
|
|
24
29
|
|
25
30
|
def download_and_parse(words, dir, extended)
|
data/lib/iciba/version.rb
CHANGED