rahu 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ecb6a0bb0bb6abb97498e21b2ef1673533e7d03
4
+ data.tar.gz: 6ebfdcdaa7625579081b493112753a452c95ae5b
5
+ SHA512:
6
+ metadata.gz: 4a0ce012ae3beb344ed631d2741ed24407fdaec6d41e19eed98230b69c2884effbcc0922d9c490ca8448c5b25f414930f597df2b30e4829f0283bfd7221c1237
7
+ data.tar.gz: cc0901cbcff30061f94c600bc06d6b8d43ee10cccbe2107680f1b010d3768ce73e36cbcc452d1baee33448578916d093422380caccf897f4fa9d031b817243b7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rahu.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 JIANG Di
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # rahu
2
+ a robot in your command line
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rh ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/rahu"
4
+
5
+ if ARGV.empty?
6
+ begin
7
+ loop do
8
+ print '> '
9
+ input = gets.chomp
10
+ # 输入为空时继续循环
11
+ next if input == ''
12
+ answer = RaHu::TuLing.new(input)
13
+ puts answer.text
14
+
15
+ answer.list.each do |k, v|
16
+ puts "#{k}: #{v.gsub('<br>', '\n')}"
17
+ end
18
+ end
19
+ rescue Interrupt
20
+ puts 'bye~'
21
+ end
22
+ else
23
+ answer = RaHu::TuLing.new(ARGV.join(' '))
24
+ puts answer.text
25
+
26
+ answer.list.each do |k, v|
27
+ puts "#{key}: #{v.gsub('<br>', '\n')}"
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Rahu
2
+ VERSION = "0.1.0"
3
+ end
data/lib/rahu.rb ADDED
@@ -0,0 +1,34 @@
1
+ require "uri"
2
+ require "net/http"
3
+ require "json"
4
+
5
+ module RaHu
6
+ API_URL = "http://www.tuling123.com/openapi/api?key=3560f55da334edb343c922cec62b5b5d&info="
7
+
8
+ class TuLing
9
+ def initialize(input)
10
+ @words = input
11
+ query_for_hash
12
+ end
13
+
14
+ def query_for_hash
15
+ query_url = API_URL + URI.escape(@words.gsub(' ', ''))
16
+ result_json = Net::HTTP.get(URI(query_url))
17
+ @result_hash = JSON.parse(result_json)
18
+ end
19
+
20
+ def text
21
+ @result_hash["text"].gsub('<br>', '\n')
22
+ end
23
+
24
+ def list
25
+ if @result_hash.key? "url"
26
+ {"链接" => @result_hash["url"]}
27
+ elsif @result_hash.key? "list"
28
+ @result_hash["list"][0]
29
+ else
30
+ {}
31
+ end
32
+ end
33
+ end
34
+ end
data/rahu.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rahu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rahu"
8
+ spec.version = Rahu::VERSION
9
+ spec.authors = ["JIANG Di"]
10
+ spec.email = ["dd19941105@gmail.com"]
11
+ spec.license = "MIT"
12
+ spec.summary = %q{a robot in your command line}
13
+ spec.homepage = "https://github.com/dd1994/rahu"
14
+
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = "rh"
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.9"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rahu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - JIANG Di
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - dd19941105@gmail.com
44
+ executables:
45
+ - rh
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - bin/rh
55
+ - lib/rahu.rb
56
+ - lib/rahu/version.rb
57
+ - rahu.gemspec
58
+ homepage: https://github.com/dd1994/rahu
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.5
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: a robot in your command line
82
+ test_files: []