cinch-magic 1.0.1 → 1.0.2

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.
@@ -4,18 +4,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cinch/plugins/magic/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "cinch-magic"
7
+ gem.name = 'cinch-magic'
8
8
  gem.version = Cinch::Plugins::Magic::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 searches http://magiccards.info/ for card information.}
12
12
  gem.summary = %q{Cinch Plugin for Magic Cards}
13
- gem.homepage = "https://github.com/bhaberer/cinch-magic"
13
+ gem.homepage = 'https://github.com/bhaberer/cinch-magic'
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
21
  gem.add_development_dependency 'rake'
21
22
  gem.add_development_dependency 'rspec'
@@ -1,2 +1,3 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'cinch/plugins/magic/version'
2
- require 'cinch/plugins/magic/magic'
3
+ require 'cinch/plugins/magic'
@@ -4,12 +4,13 @@ require 'cinch/toolbox'
4
4
  require 'cinch/cooldown'
5
5
 
6
6
  module Cinch::Plugins
7
+ # Cinch Plugin to looking MTG cards
7
8
  class Magic
8
9
  include Cinch::Plugin
9
10
 
10
11
  enforce_cooldown
11
12
 
12
- self.help = "Use .mtg <card name> to see the info for that card."
13
+ self.help = 'Use .mtg <card name> to see the info for that card.'
13
14
 
14
15
  match /mtg (.*)/
15
16
 
@@ -21,21 +22,21 @@ module Cinch::Plugins
21
22
 
22
23
  def get_card(term)
23
24
  # Fetch the html for the search term
24
- data = get_card_data(term)
25
+ data = card_data(term)
25
26
 
26
27
  # Catch nil responses.
27
28
  return '[Magic] Card not found, or problem fetching page.' if data.nil?
28
29
 
29
30
  # Build card string
30
- card = "#{get_card_name(data)} [#{get_card_info(data)}] - #{get_card_text(data)}"
31
+ card = "#{card_name(data)} [#{card_info(data)}] - #{card_text(data)}"
31
32
 
32
33
  # Truncate if it's super long
33
34
  card = Cinch::Toolbox.truncate(card, 300)
34
35
 
35
- return "[Magic] #{card} [#{get_card_link(data)}]"
36
+ "[Magic] #{card} [#{card_link(data)}]"
36
37
  end
37
38
 
38
- def get_card_info(data)
39
+ def card_info(data)
39
40
  text = data[/<p[^>]*>([^<]+)<\/p>/, 1]
40
41
 
41
42
  # Replace Newlines, unicode lines, total mana, and large spaces.
@@ -47,44 +48,48 @@ module Cinch::Plugins
47
48
  # Remove pesky whitespace that might have snuck in...
48
49
  text.strip!
49
50
 
50
- return text
51
+ text
51
52
  rescue
52
- debug "Error getting this card's info"
53
+ debug 'Error getting the card info'
54
+ return ''
53
55
  end
54
56
 
55
- def get_card_name(data)
56
- return data[/<a href=[^>]*>([^<]+)<\/a>/, 1]
57
+ def card_name(data)
58
+ data[/<a href=[^>]*>([^<]+)<\/a>/, 1]
57
59
  rescue
58
- debug "Error finding this card's name"
60
+ debug 'Error finding the card name'
61
+ return ''
59
62
  end
60
63
 
61
- def get_card_link(data)
62
- return "http://magiccards.info" + data.match(/<a href="([^>]*)">[^<]+<\/a>/)[1]
64
+ def card_link(data)
65
+ "http://magiccards.info#{data[/<a href="([^>]*)">[^<]+<\/a>/, 1]}"
63
66
  rescue
64
- debug "Error finding this card's url"
67
+ debug 'Error finding the card url'
68
+ return ''
65
69
  end
66
70
 
67
- def get_card_text(data)
68
- return data.match(/<p class="ctext"><b[^>]*>(.+)<\/b><\/p>/)[1].gsub(/<br><br>/, ' ')
71
+ def card_text(data)
72
+ data[%r(<p class="ctext"><b[^>]*>(.+)</b></p>), 1].gsub(/<br><br>/, ' ')
69
73
  rescue
70
- debug "Error finding this card's description"
74
+ debug 'Error finding the card description'
75
+ return ''
71
76
  end
72
77
 
73
- def get_card_data(term)
78
+ def card_data(term)
74
79
  # URI Encode the term and build the URL
75
- term = URI.escape("!#{term}", Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
80
+ term = URI.escape("!#{term}",
81
+ Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
76
82
  url = "http://magiccards.info/query?q=#{term}"
77
83
 
78
84
  # Make sure the URL is legit
79
- url = URI::extract(url, ["http", "https"]).first
85
+ url = URI.extract(url, %w(http https)).first
80
86
 
81
87
  # Grab the html block because magiccards.info fucking loves tables
82
88
  # and hates helpful ids and classnames
83
- return Cinch::Toolbox.get_html_element(url, '//table[3]/tr/td[2]', :xpath_full)
84
-
89
+ Cinch::Toolbox.get_html_element(url, '//table[3]/tr/td[2]', :xpath_full)
85
90
  rescue
86
91
  debug "Error looking up card: #{term}"
87
- return nil
92
+ return
88
93
  end
89
94
  end
90
95
  end
@@ -1,7 +1,9 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Cinch
2
3
  module Plugins
4
+ # Version info
3
5
  class Magic
4
- VERSION = "1.0.1"
6
+ VERSION = '1.0.2'
5
7
  end
6
8
  end
7
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
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-07-10 00:00:00.000000000 Z
12
+ date: 2014-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -138,12 +138,13 @@ files:
138
138
  - Rakefile
139
139
  - cinch-magic.gemspec
140
140
  - lib/cinch-magic.rb
141
- - lib/cinch/plugins/magic/magic.rb
141
+ - lib/cinch/plugins/magic.rb
142
142
  - lib/cinch/plugins/magic/version.rb
143
143
  - spec/cinch-magic_spec.rb
144
144
  - spec/spec_helper.rb
145
145
  homepage: https://github.com/bhaberer/cinch-magic
146
- licenses: []
146
+ licenses:
147
+ - MIT
147
148
  post_install_message:
148
149
  rdoc_options: []
149
150
  require_paths:
@@ -169,3 +170,4 @@ summary: Cinch Plugin for Magic Cards
169
170
  test_files:
170
171
  - spec/cinch-magic_spec.rb
171
172
  - spec/spec_helper.rb
173
+ has_rdoc: