ruboty-rurema 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruboty/rurema.rb +20 -4
- data/lib/ruboty/rurema/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c56322e315bf247b29a7de78a082233acd499b0f72bbe543d3d1b81e1eedc929
|
4
|
+
data.tar.gz: 8168d7ba97c04e6baa4883b1983286ca131f714516b9907866c38fdd1626677f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c4ed4e2f89dbf363af563a10466d6c6240cba786fcf85e7973aeb30e3c1890dd31a3579265725448d0f578e807dc03f711478f02c2000660e1bbe080f13ba46
|
7
|
+
data.tar.gz: c2bafcaff1e7484ea014ed70254be47217b91af94e7fe587748758afbf67a8e2e5b2d09858a4ed4ef492f8d7729c3dde317c453f45aa967b4dc671063010dae4
|
data/lib/ruboty/rurema.rb
CHANGED
@@ -5,6 +5,8 @@ require 'uri'
|
|
5
5
|
require 'json'
|
6
6
|
require 'open-uri'
|
7
7
|
require 'cgi'
|
8
|
+
require 'optparse'
|
9
|
+
require 'shellwords'
|
8
10
|
|
9
11
|
module Ruboty
|
10
12
|
module Handlers
|
@@ -21,6 +23,7 @@ module Ruboty
|
|
21
23
|
|
22
24
|
def rurema(message)
|
23
25
|
query = message.match_data['query']
|
26
|
+
query, params = parse_query(query)
|
24
27
|
url = build_url(query)
|
25
28
|
if url && exist_resource?(url)
|
26
29
|
message.reply url
|
@@ -34,10 +37,23 @@ module Ruboty
|
|
34
37
|
return
|
35
38
|
end
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
resp = params[:n].to_i.times.map do |idx|
|
41
|
+
url = resp.dig(:entries, idx, :documents, -1, :url)
|
42
|
+
next unless url
|
43
|
+
# BUG: rurema searcher returns URL with 'https://docs.ruby-lang.org/ja/search/', so we need removing it.
|
44
|
+
url.sub('docs.ruby-lang.org/ja/search/http://', '')
|
45
|
+
end.compact
|
46
|
+
message.reply resp.join("\n")
|
47
|
+
end
|
48
|
+
|
49
|
+
private def parse_query(query)
|
50
|
+
args = Shellwords.split(query)
|
51
|
+
opt = OptionParser.new
|
52
|
+
params = {n: 1}
|
53
|
+
opt.on("-n COUNT")
|
54
|
+
opt.parse!(args, into: params)
|
55
|
+
|
56
|
+
return args.join(' '), params
|
41
57
|
end
|
42
58
|
|
43
59
|
private def build_url(query)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-rurema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Pocke Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|