cinch-wikipedia 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,25 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cinch/plugins/wikipedia/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "cinch-wikipedia"
7
+ gem.name = 'cinch-wikipedia'
8
8
  gem.version = Cinch::Plugins::Wikipedia::VERSION
9
- gem.authors = ["Brian Haberer"]
10
- gem.email = ["bhaberer@gmail.com"]
9
+ gem.authors = ['Brian Haberer']
10
+ gem.email = ['bhaberer@gmail.com']
11
11
  gem.description = %q{Cinch plugin that fetches a truncated blurb from the head of a wikipedia page.}
12
12
  gem.summary = %q{Cinch Wikipedia Plugin}
13
- gem.homepage = "https://github.com/bhaberer/cinch-wikipedia"
13
+ gem.homepage = 'https://github.com/bhaberer/cinch-wikipedia'
14
+ gem.license = 'MIT'
14
15
 
15
16
  gem.files = `git ls-files`.split($/)
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
19
+ gem.require_paths = ['lib']
19
20
 
20
- gem.add_development_dependency 'rake'
21
- gem.add_development_dependency 'rspec'
22
- gem.add_development_dependency 'coveralls'
23
- gem.add_development_dependency 'cinch-test'
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
23
+ gem.add_development_dependency 'coveralls'
24
+ gem.add_development_dependency 'cinch-test'
24
25
 
25
- gem.add_dependency 'cinch', '~> 2.0.5'
26
- gem.add_dependency 'cinch-toolbox', '~> 1.0.3'
27
- gem.add_dependency 'cinch-cooldown', '~> 1.0.1'
26
+ gem.add_dependency 'cinch', '~> 2.0.12'
27
+ gem.add_dependency 'cinch-toolbox', '~> 1.1.0'
28
+ gem.add_dependency 'cinch-cooldown', '~> 1.1.1'
28
29
  end
@@ -1,7 +1,9 @@
1
+ # -*- coding: utf-8 -*-
1
2
  module Cinch
2
3
  module Plugins
4
+ # Versioning information
3
5
  class Wikipedia
4
- VERSION = "1.0.1"
6
+ VERSION = '1.0.3'
5
7
  end
6
8
  end
7
9
  end
@@ -4,12 +4,13 @@ require 'cinch/toolbox'
4
4
  require 'cinch/cooldown'
5
5
 
6
6
  module Cinch::Plugins
7
+ # Plugin to allow users to search wikipedia.
7
8
  class Wikipedia
8
9
  include Cinch::Plugin
9
10
 
10
11
  enforce_cooldown
11
12
 
12
- self.help = "Use .wiki <term> to see the Wikipedia info for that term."
13
+ self.help = 'Use .wiki <term> to see the Wikipedia info for that term.'
13
14
 
14
15
  match /wiki (.*)/
15
16
  match /wikipedia (.*)/
@@ -20,43 +21,46 @@ module Cinch::Plugins
20
21
  end
21
22
 
22
23
  def execute(m, term)
23
- m.reply get_def(term)
24
+ m.reply wiki(term)
24
25
  end
25
26
 
26
27
  private
27
28
 
28
- def get_def(term)
29
+ def wiki(term)
29
30
  # URI Encode
30
31
  term = URI.escape(term, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
31
32
  url = "http://en.wikipedia.org/w/index.php?search=#{term}"
32
33
 
34
+ # Truncate text and url if they are too long
35
+ text = Cinch::Toolbox.truncate(get_def(term, url), @max_length)
36
+ url = Cinch::Toolbox.shorten(url)
37
+
38
+ "Wikipedia ∴ #{text} [#{url}]"
39
+ end
40
+
41
+ def get_def(term, url)
33
42
  cats = Cinch::Toolbox.get_html_element(url, '#mw-normal-catlinks')
34
43
  if cats && cats.include?('Disambiguation')
35
44
  wiki_text = "'#{term} is too vague and lead to a disambiguation page."
36
45
  else
37
- # Grab the text
38
46
  wiki_text = Cinch::Toolbox.get_html_element(url, '#mw-content-text p')
39
-
40
- # Check for search errors
41
- return not_found(wiki_text, url) if wiki_text.nil? || wiki_text.include?('Help:Searching')
47
+ if wiki_text.nil? || wiki_text.include?('Help:Searching')
48
+ return not_found(wiki_text, url)
49
+ end
42
50
  end
43
-
44
- # Truncate text and url if they are too long
45
- text = Cinch::Toolbox.truncate(wiki_text, @max_length)
46
- url = Cinch::Toolbox.shorten(url)
47
-
48
- return "Wikipedia ∴ #{text} [#{url}]"
51
+ wiki_text
49
52
  end
50
53
 
51
54
  def not_found(wiki_text, url)
52
- msg = "I couldn't find anything for that search"
53
- if alt_term_text = Cinch::Toolbox.get_html_element(url, '.searchdidyoumean')
55
+ msg = "I couldn't find anything for that search, "
56
+ alt_term_text = Cinch::Toolbox.get_html_element(url, '.searchdidyoumean')
57
+ if alt_term_text
54
58
  alt_term = alt_term_text[/\ADid you mean: (\w+)\z/, 1]
55
- msg << ", did you mean '#{alt_term}'?"
59
+ msg << "did you mean '#{alt_term}'?"
56
60
  else
57
- msg << ", sorry!"
61
+ msg << 'sorry!'
58
62
  end
59
- return msg
63
+ msg
60
64
  end
61
65
  end
62
66
  end
@@ -1,2 +1,3 @@
1
- require "cinch/plugins/wikipedia/version"
2
- require "cinch/plugins/wikipedia/wikipedia"
1
+ # -*- coding: utf-8 -*-
2
+ require 'cinch/plugins/wikipedia/version'
3
+ require 'cinch/plugins/wikipedia'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-wikipedia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-21 00:00:00.000000000 Z
12
+ date: 2014-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 2.0.5
85
+ version: 2.0.12
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 2.0.5
93
+ version: 2.0.12
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: cinch-toolbox
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 1.0.3
101
+ version: 1.1.0
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ dependencies:
106
106
  requirements:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: 1.0.3
109
+ version: 1.1.0
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: cinch-cooldown
112
112
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 1.0.1
117
+ version: 1.1.1
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 1.0.1
125
+ version: 1.1.1
126
126
  description: Cinch plugin that fetches a truncated blurb from the head of a wikipedia
127
127
  page.
128
128
  email:
@@ -139,12 +139,13 @@ files:
139
139
  - Rakefile
140
140
  - cinch-wikipedia.gemspec
141
141
  - lib/cinch-wikipedia.rb
142
+ - lib/cinch/plugins/wikipedia.rb
142
143
  - lib/cinch/plugins/wikipedia/version.rb
143
- - lib/cinch/plugins/wikipedia/wikipedia.rb
144
144
  - spec/cinch-wikipedia_spec.rb
145
145
  - spec/spec_helper.rb
146
146
  homepage: https://github.com/bhaberer/cinch-wikipedia
147
- licenses: []
147
+ licenses:
148
+ - MIT
148
149
  post_install_message:
149
150
  rdoc_options: []
150
151
  require_paths: