youdao_dict_cli 0.0.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/ydict +41 -0
  3. data/lib/dict.rb +21 -0
  4. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ac241befdcb95653b688a8c61a860e1a8fb84596
4
+ data.tar.gz: eea0511c146160379f4105debe3f660f5a57c11b
5
+ SHA512:
6
+ metadata.gz: 053cebc6697073c41af4898ac6e645d2b81b013cafdb48e0495bcb163c01b0ee3cc41b7491418863c1e63bf52e1b1da7fd512dd0c70dd3958f3e92f1ef5c9e04
7
+ data.tar.gz: 063b3e76d8b4c1c341e6d245c8afc345223afbee729c01602318a16a3df0d476378b13609860174e221ad5f226376c40bd29a30c693c69b54fb7eac66f79de62
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dict'
4
+
5
+ # Linux terminal color codes
6
+ RESET = "\e[0m"
7
+ BLACK = "\e[30m"
8
+ RED = "\e[31m"
9
+ GREEN = "\e[32m"
10
+ YELLOW = "\e[33m"
11
+ BLUE = "\e[34m"
12
+ MAGENTA = "\e[35m"
13
+ CYAN = "\e[36m"
14
+ # Prompt
15
+ PROMPT = ">> "
16
+ # Exit codes defination
17
+ EXIT = "bye"
18
+
19
+ def usage
20
+ puts <<-END.gsub(/^\s*\|/, '')
21
+ |Usage:
22
+ |#{File.basename($0).to_s} [arg]
23
+ | no arguments: starting translating! enter bye to exit the program
24
+ | any arguments: display this help
25
+ END
26
+ end
27
+
28
+ if ARGV.length > 0
29
+ usage
30
+ else
31
+ while true
32
+ print PROMPT
33
+ word = gets.chomp.force_encoding('ASCII-8BIT')
34
+ if EXIT == word
35
+ puts "#{CYAN}bye ^_^#{RESET}"
36
+ exit 0
37
+ else
38
+ translate(word) { |t| puts "#{RED}#{t[0]} #{GREEN}#{t[1..-1].join}#{RESET}" }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # a simple ruby script for translating in cli
3
+ # by delta
4
+
5
+ require 'open-uri'
6
+ require 'rexml/document'
7
+
8
+ # URL prefix, URL suffix, doc elements defination
9
+ PREFIX = 'http://dict.youdao.com/search?q='
10
+ SUFFIX = '&xmlDetail=true&doctype=xml'
11
+ ELE = 'yodaodict/custom-translation/translation/content/'
12
+
13
+ def translate(word)
14
+ url = PREFIX + word + SUFFIX
15
+ xml = URI.parse(URI::encode(url)).read
16
+ doc = REXML::Document.new(xml)
17
+ doc.elements.each(ELE) do |e|
18
+ text = e.text.to_s.split
19
+ yield text
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: youdao_dict_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - delta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple youdao dictionary for cli using
14
+ email: delta4d@gmail.com
15
+ executables:
16
+ - ydict
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/dict.rb
21
+ - bin/ydict
22
+ homepage: https://github.com/delta4d/youdao-dict-cli
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.0.10
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Youdao dictionary cli
46
+ test_files: []