han 0.0.1

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 (6) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +19 -0
  3. data/bin/han +4 -0
  4. data/lib/han/version.rb +3 -0
  5. data/lib/han.rb +51 -0
  6. metadata +105 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a54f3f62ecc35a817ca9fb1361452bf668c24dcf
4
+ data.tar.gz: 07ab2df9060d4bf9dca8ddf26e478a97c3e40b71
5
+ SHA512:
6
+ metadata.gz: f56f9675aed9c243555a2f28dedc0233fee979429d53552db136fb881064fc3a75297ad3c92064d6f7a04244f00390b37601648233b76ddcddcdae75b52a1dda
7
+ data.tar.gz: afded6b92edbcb756cfe2b138f092bbc3f2248f98fe22192f54d8c531e4eb2e9efca7b16c68f30616fbd5165f6a3014387359eb1efef74e062cc92bf8c3fd695
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Han
2
+
3
+ Command line Chinese dictionary
4
+
5
+ ## Installation
6
+
7
+ $ gem install han
8
+
9
+ ## Usage
10
+
11
+ $ han 汉
12
+
13
+ ## Contributing
14
+
15
+ 1. Fork it ( https://github.com/lanjian/han/fork )
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
18
+ 4. Push to the branch (`git push origin my-new-feature`)
19
+ 5. Create a new Pull Request
data/bin/han ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'han'
4
+ Han::CLI.start
@@ -0,0 +1,3 @@
1
+ module Han
2
+ VERSION = "0.0.1"
3
+ end
data/lib/han.rb ADDED
@@ -0,0 +1,51 @@
1
+ # encoding=utf-8
2
+ require "han/version"
3
+
4
+ require 'thor'
5
+ require 'nokogiri'
6
+ require 'open-uri'
7
+ require 'net/http'
8
+
9
+ module Han
10
+ class CLI < Thor::Group
11
+
12
+ argument :character
13
+
14
+ def process
15
+ uri = URI(URI::encode("http://www.zdic.net/sousuo/?q=#{character}"))
16
+ res = Net::HTTP.get_response(uri)
17
+
18
+ doc = Nokogiri::HTML(open("http://www.zdic.net#{res['location']}"))
19
+
20
+ lines = doc.css('p').to_a
21
+ lines.shift
22
+ char = lines.shift
23
+ trad = traditional(lines)
24
+
25
+ if trad
26
+ say "#{char.content[2..-1]}#{trad}"
27
+ else
28
+ say "#{char.content[2..-1]}"
29
+ end
30
+
31
+ py = lines.shift
32
+ say py.content.split[0]
33
+ say
34
+ lines.each { |l| say l.content[1..-1] if l.content[0] == ' ' }
35
+ end
36
+
37
+ no_tasks do
38
+ def traditional(lines)
39
+ line = lines.shift
40
+ matches = line.content.match(/^(.*)$/)
41
+ if matches
42
+ return line.content
43
+ end
44
+
45
+ lines.unshift(line)
46
+ return nil
47
+ end
48
+ end
49
+
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: han
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jack Huang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.19'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.19'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ''
70
+ email:
71
+ - jackhxs@gmail.com
72
+ executables:
73
+ - han
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - README.md
78
+ - bin/han
79
+ - lib/han.rb
80
+ - lib/han/version.rb
81
+ homepage:
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.2.2
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Command line Chinese dictionary
105
+ test_files: []