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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8e3e12d8a36e5dc4f5aa2a6c1b1a7b5dbbece4db23474f346f40a31aa168cb2
4
- data.tar.gz: a793d127cf88ca99c59b9915cdbfe44911b6c37b429a055e69b3a5cb25522fa1
3
+ metadata.gz: c56322e315bf247b29a7de78a082233acd499b0f72bbe543d3d1b81e1eedc929
4
+ data.tar.gz: 8168d7ba97c04e6baa4883b1983286ca131f714516b9907866c38fdd1626677f
5
5
  SHA512:
6
- metadata.gz: ff25b0cd3514ef6f241abf3eac99e070dbd2985f99c3b76e3a19d0e081b722e51decb5956c4b8b7d2464c7e993b82a69ade34d3bf0fc74eefddf18005c7a8576
7
- data.tar.gz: fe3993adb4a312165495a02bfcaf091d1d3ee77ee94eaac21f860a2dd17c578eadc4bf1c5d8aedf5a6e28b2c8b7f1cf69d75b3ead323c9748fccde1e311a467d
6
+ metadata.gz: 1c4ed4e2f89dbf363af563a10466d6c6240cba786fcf85e7973aeb30e3c1890dd31a3579265725448d0f578e807dc03f711478f02c2000660e1bbe080f13ba46
7
+ data.tar.gz: c2bafcaff1e7484ea014ed70254be47217b91af94e7fe587748758afbf67a8e2e5b2d09858a4ed4ef492f8d7729c3dde317c453f45aa967b4dc671063010dae4
@@ -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
- url = resp.dig(:entries, 0, :documents, -1, :url)
38
- # BUG: rurema searcher returns URL with 'https://docs.ruby-lang.org/ja/search/', so we need removing it.
39
- url.sub!('docs.ruby-lang.org/ja/search/http://', '')
40
- message.reply url
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)
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Rurema
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
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.1.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-08-24 00:00:00.000000000 Z
11
+ date: 2019-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty