Permalink
Browse files

modify std output display

  • Loading branch information...
1 parent a3d03cf commit 2306d3ae13018f537b46940af548b2117a45ec89 @vkill committed Dec 2, 2011
Showing with 34 additions and 6 deletions.
  1. +4 −0 CHANGELOG
  2. +28 −5 bin/youdao_fanyi
  3. +1 −1 lib/youdao_fanyi/version.rb
  4. +1 −0 youdao_fanyi.gemspec
View
@@ -1,3 +1,7 @@
+== 0.1.2
+
+* modify bin display
+
== 0.1.1
* modify bin/youdao_fanyi require load order, run fast
View
@@ -28,19 +28,42 @@ STDERR.puts "fanyi.youdao.com API key is required" unless options[:key]
STDERR.puts "fanyi.youdao.com API keyfrom is required" unless options[:keyfrom]
STDERR.puts "At least one string to translate is required" unless ARGV.size >= 1
-require "pp"
+
$:.push File.expand_path("../../lib", __FILE__)
require "youdao_fanyi"
+require "vkill_gems_methods/std"
YoudaoFanyi.configure do |config|
config.api_keys = [
{ "keyfrom" => options[:keyfrom], "key" => options[:key] }
]
end
-YoudaoFanyi::Translator.translate(*ARGV) do |results|
-# puts results.translation
- pp results.results
- puts "======================================="
+YoudaoFanyi::Translator.translate(*ARGV) do |connector|
+ STDOUT.puts "======================================="
+ if connector.error_code == 0
+ STDOUT.puts VkillGemsMethods::STD::Display.new(
+ :header => :translation, :text => connector.translation,
+ :color => :green, :rjust_integer => 12
+ ).output
+ STDOUT.puts VkillGemsMethods::STD::Display.new(
+ :header => :phonetic, :text => (connector.results['basic']['phonetic'] rescue ""),
+ :color => :green, :rjust_integer => 12
+ ).output
+ STDOUT.puts VkillGemsMethods::STD::Display.new(
+ :header => :explains, :text => (connector.results['basic']['explains'] rescue ""),
+ :color => :green, :rjust_integer => 12
+ ).output
+ else
+ STDOUT.puts VkillGemsMethods::STD::Display.new(
+ :header => :error_code, :text => connector.error_code,
+ :color => :red, :rjust_integer => 12
+ ).output
+ STDOUT.puts VkillGemsMethods::STD::Display.new(
+ :header => :query, :text => connector.query,
+ :color => :green, :rjust_integer => 12
+ ).output
+ end
+ STDOUT.puts "======================================="
end
@@ -1,6 +1,6 @@
#encoding: utf-8
module YoudaoFanyi
- VERSION = "0.1.1"
+ VERSION = "0.1.2"
end
View
@@ -28,5 +28,6 @@ Gem::Specification.new do |gem|
gem.add_dependency "httparty", "~> 0.8.1"
gem.add_dependency "activesupport", "~> 3.0"
+ gem.add_dependency "vkill_gems_methods", "~> 0.1.2"
end

0 comments on commit 2306d3a

Please sign in to comment.