iciba 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/iciba.gemspec +1 -0
- data/lib/iciba/fanyi.rb +10 -9
- data/lib/iciba/tools.rb +2 -1
- data/lib/iciba/version.rb +1 -1
- metadata +17 -1
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
|
|
21
21
|
Command-line usage:
|
22
22
|
|
23
23
|
$ fy words to be translated
|
24
|
-
$ fy english -
|
24
|
+
$ fy english -s #for first word to be returned
|
25
25
|
$ fy You will need to have root access to do this. -p #to get pinyin for chinese characters, (hopefully fy.iciba.com is correct)
|
26
26
|
$ fy http://www.chinadaily.com.cn/business/2012-09/07/content_15742188.htm -l #to download links
|
27
27
|
|
data/iciba.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_dependency(%q<hashie>, [">= 0"])
|
19
19
|
gem.add_dependency(%q<yajl-ruby>, [">= 0"])
|
20
20
|
gem.add_dependency(%q<nokogiri>, [">= 0"])
|
21
|
+
gem.add_dependency(%q<hpricot>, [">= 0"])
|
21
22
|
gem.add_dependency(%q<ruby-readability>, [">= 0"])
|
22
23
|
gem.add_dependency(%q<string_to_pinyin>, ['>= 0'])
|
23
24
|
gem.add_development_dependency(%q<pry>, ['>= 0'])
|
data/lib/iciba/fanyi.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'string_to_pinyin'
|
3
|
+
|
3
4
|
module Iciba
|
4
5
|
class Fanyi
|
5
6
|
attr_accessor :response, :html, :dir, :result
|
6
7
|
|
7
8
|
|
8
9
|
|
9
|
-
def initialize(words, dir='auto',
|
10
|
-
puts '------------------------------------------------------------------------------------' if
|
10
|
+
def initialize(words, dir='auto', logs=false, extended=false, pinyin=false)
|
11
|
+
puts '------------------------------------------------------------------------------------' if logs
|
11
12
|
# puts if bingit
|
12
13
|
words = words.dup.force_encoding("UTF-8")
|
13
|
-
puts wrap_text(words, 40) if words.contains_cjk? &&
|
14
|
-
puts wrap_text(words) unless words.contains_cjk? &&
|
14
|
+
puts wrap_text(words, 40) if words.contains_cjk? && logs
|
15
|
+
puts wrap_text(words) unless words.contains_cjk? && logs
|
15
16
|
# puts '------------------------------------------------------------------------------------' if words.contains_cjk? && bin && pinyin
|
16
|
-
puts words.to_pinyin if words.contains_cjk? &&
|
17
|
-
puts '------------------------------------------------------------------------------------' if
|
17
|
+
puts words.to_pinyin if words.contains_cjk? && logs && pinyin
|
18
|
+
puts '------------------------------------------------------------------------------------' if logs
|
18
19
|
download_and_parse(words, dir, extended)
|
19
|
-
puts wrap_text(self.result) if
|
20
|
-
puts if self.result.contains_cjk? &&
|
20
|
+
puts wrap_text(self.result) if logs
|
21
|
+
puts if self.result.contains_cjk? && logs && pinyin
|
21
22
|
puts wrap_text(self.result.strip.gsub("\r\n", '|newline|').to_pinyin.gsub('|newline|', "\r\n\r\n"), 40) if self.result.contains_cjk? && pinyin && bin
|
22
|
-
puts '------------------------------------------------------------------------------------' if
|
23
|
+
puts '------------------------------------------------------------------------------------' if logs
|
23
24
|
return self.result
|
24
25
|
end
|
25
26
|
|
data/lib/iciba/tools.rb
CHANGED
@@ -3,6 +3,7 @@ require 'yajl'
|
|
3
3
|
require 'hashie'
|
4
4
|
require 'curb'
|
5
5
|
require 'nokogiri'
|
6
|
+
require 'hpricot'``
|
6
7
|
module Iciba
|
7
8
|
module Tools
|
8
9
|
|
@@ -68,7 +69,7 @@ module Iciba
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def self.doc(html)
|
71
|
-
|
72
|
+
Hpricot(html)
|
72
73
|
end
|
73
74
|
end
|
74
75
|
end
|
data/lib/iciba/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iciba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: hpricot
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: ruby-readability
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|