iciba 0.0.6 → 0.0.7

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/README.md CHANGED
@@ -24,7 +24,7 @@ Command-line usage:
24
24
  $ fy 'english' # for single word answers
25
25
  $ fy 'english' -e #for complete definition if available
26
26
  $ fy http://www.chinadaily.com.cn/business/2012-09/07/content_15742188.htm -l #to download links
27
- $ fy http://www.chinadaily.com.cn/business/2012-09/07/content_15742188.htm -l -r #to translate the links
27
+ $ fy http://www.chinadaily.com.cn/business/2012-09/07/content_15742188.htm -l -r #to translate the links TODO
28
28
 
29
29
  Ruby usage:
30
30
 
data/bin/fy CHANGED
@@ -11,6 +11,7 @@ OptionParser.new do |opts|
11
11
  opts.on("-l", "--links", "Download links?") { |b| $links = true }
12
12
  opts.on("-i", "--interactive", "Download links?") { |b| $interactive = true }
13
13
  opts.on("-e", "--extended", "Extended") { |b| $extended = true }
14
+ opts.on("-p", "--pinyin", "Pinyin") { |b| $pinyin = true }
14
15
  opts.on("-h", "--help", "go to fy.iciba.com") do
15
16
  puts opts
16
17
  exit 0
@@ -50,7 +51,8 @@ def loop_through_links(links)
50
51
  end
51
52
  end
52
53
 
54
+ pinyin = ($pinyin ? true : false)
53
55
  extended = ($extended ? true : false)
54
56
 
55
- Iciba::Fanyi.new(ARGV.first, 'auto', true, extended)
57
+ Iciba::Fanyi.new(ARGV.first, 'auto', true, extended, pinyin)
56
58
  loop_through_links(links) if ($links && links.size > 0)
@@ -20,4 +20,5 @@ Gem::Specification.new do |gem|
20
20
  gem.add_dependency(%q<nokogiri>, [">= 0"])
21
21
  # gem.add_dependency(%q<pinyin>, [">= 0"])
22
22
  gem.add_dependency(%q<ruby-readability>, [">= 0"])
23
+ gem.add_dependency(%q<string_to_pinyin>, ['>= 0'])
23
24
  end
@@ -1,18 +1,22 @@
1
1
  # coding: utf-8
2
+ require 'string_to_pinyin'
2
3
  module Iciba
3
4
  class Fanyi
4
5
  attr_accessor :response, :html, :dir, :result
5
6
 
6
7
 
7
8
 
8
- def initialize(words, dir='auto', bin=false, extended=false)
9
+ def initialize(words, dir='auto', bin=false, extended=false, pinyin=false)
9
10
  puts '------------------------------------------------------------------------------------' if bin
10
11
  # puts if bingit
11
12
  puts wrap_text(words, 40) if words.contains_cjk? && bin
12
13
  puts wrap_text(words) unless words.contains_cjk? && bin
14
+ puts '------------------------------------------------------------------------------------' if words.contains_cjk? && bin && pinyin
15
+ puts words.to_pinyin if words.contains_cjk? && bin && pinyin
13
16
  puts '------------------------------------------------------------------------------------' if bin
14
17
  download_and_parse(words, dir, extended)
15
18
  puts wrap_text(self.result) if bin
19
+ puts self.result.to_pinyin if self.result.contains_cjk? && bin
16
20
  puts '------------------------------------------------------------------------------------' if bin
17
21
  return self.result
18
22
  end
@@ -25,6 +29,14 @@ module Iciba
25
29
  def self.check_char(str)
26
30
  str.contains_cjk?
27
31
  end
32
+
33
+ def print_pinyin(words)
34
+ puts words.string_to_pinyin
35
+ end
36
+
37
+ def self.print_pinyin(words)
38
+ puts words.string_to_pinyin
39
+ end
28
40
 
29
41
 
30
42
  def download_and_parse(words, dir, extended)
@@ -1,3 +1,3 @@
1
1
  module Iciba
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
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.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-09 00:00:00.000000000 Z
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: curb
@@ -91,6 +91,22 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: string_to_pinyin
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
94
110
  description: iciba wrapper
95
111
  email:
96
112
  - ussballantyne@gmail.com