botemon 0.2.4 → 0.3

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODk1NDM4YzcwYWRkZWVmNzFmNTg0MmRhNTc1MjZkNWE4Njc5YmM5ZA==
4
+ MTQ0ZGE1YzRlMjNlMTY1ZTRiMDA3ZTUzY2FhMmZmOGE2N2I0N2MxMQ==
5
5
  data.tar.gz: !binary |-
6
- MTg4NDUxZmFjNzg2NGY4ZmViNWMyMjEyODYyY2Q1MDYzYWFjZWQ2ZA==
6
+ ZDk0ODJiNWJlOGNkNWZjZTk0YjU3NjFlZmQxMDkwMGNkNTM1OTA1Mg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZTZkYjkwOGRlYjZhNDM4MzU5MTQ1N2ExODk5MDQ0YTIyNGJkZWJlZjI2MzVi
10
- OGUwNDc5MGExZDZmYTM1ZWIwMDYxNWFkYmJkZTNjYmQzOGIzYjJmOTM0M2Y3
11
- ZjE3ZDAyYmVmMjkyNmFiNzNlMDBmNGYzYWE5NmQ5YmQ1MDkyODg=
9
+ MWY4NTY4NmJmNWE5NzU0NGVjODY0YmNhNzAzNDAxNWEzYmE1MzAzODRjNjI3
10
+ YTljZmRlY2I0MGZlMTQ1MzEzZTRlOThjZTAwM2U1MmI1OGU5NTFlNjcxYzMw
11
+ OWNjOTc0OTQwYWEzZGI2ZGQ5OWY2NjA0NGRkZjVlZDgwYjU2YTE=
12
12
  data.tar.gz: !binary |-
13
- NjliN2Y0MjQyN2FlZWRkYjNmOTU0Mjc5ZTAyZmU0YzU4NTYyNjU2NjFiNjlm
14
- ZDc3MzgxZjE0NDBhNDRjNzQ4YmEwMGQ1NzMwZTkwYzc0ODgwYjk3MzdiMDUy
15
- NGVmZjE1MzFiMWYwYjAyYmQzZWEzYjI3MGYzNDhkYjQzMTdmNDU=
13
+ YjNjNjEwZTM5ODYzNzU3Y2E2M2QwNTU3MDdlODhmMDQ1ZDUzMTU4ODg1MTE4
14
+ ZDdkNGY2NTQ1ZmE0OTRjYWRmMWFjZTQ3YjE0NmFlMmViMjVmYjU0ZTc3NTQ0
15
+ ZThlM2M3ZGMwZjlmYThmZTA0YTEyMjE3OWNhYmIxNzQ0YWZmMzA=
data/bin/botemon CHANGED
@@ -61,8 +61,13 @@ Cinch::Bot.new {
61
61
  if name == nil
62
62
  m.reply Format(:red, 'Pokémon not found.')
63
63
  else
64
- moveset = Movedex.get name, tier
65
- m.reply Format(:red, moveset ? moveset.to_s : 'Moveset not found.')
64
+ movesets = Movedex.get name, tier
65
+ if movesets != nil || movesets.any?
66
+ m.reply Format(:red, "--- #{movesets.first.pokemon} (#{movesets.first.tier}) ---")
67
+ movesets.each { |moveset| m.reply Format(:red, " -- #{moveset.name} --\n#{moveset.to_s.split("\n").map { |l| Format(:red, l) }.join("\n")}\n") }
68
+ else
69
+ m.reply Format(:red, 'Moveset not found.')
70
+ end
66
71
  end
67
72
  end
68
73
 
@@ -25,36 +25,65 @@ class Movedex
25
25
  return nil
26
26
  end
27
27
  end
28
-
29
- def self.tiers
30
- ['uber', 'ou', 'bl', 'uu', 'bl2', 'ru', 'nu', 'lc', 'limbo', 'nfe']
31
- end
32
28
 
33
29
  def self.get(name, tier)
34
- return nil if name == nil || tier == nil || !Movedex.tiers.include?(tier.downcase)
30
+ return nil if name == nil || tier == nil
35
31
 
36
32
  begin
37
33
  url = URI::encode "http://www.smogon.com/bw/pokemon/#{name}/#{tier}"
38
34
 
39
- moveset = Moveset.new
40
35
  smogon = Nokogiri::HTML(open(url))
41
36
  rescue
42
37
  return nil
43
38
  end
44
39
 
45
- moveset.pokemon = smogon.xpath('//td[@class="header"]/h1').last.text
46
- moveset.name = smogon.xpath('//td[@class="name"]/h2').first.text
47
- moveset.tier = smogon.xpath('//table[@class="info"]/tr/td/a').last.text
48
-
49
- section = smogon.xpath('//table[@class="info strategyheader"]/tr')[1].children
50
- moveset.item = section[2].text.gsub(/\n/m, '').gsub(/\t/m, '').strip
51
- moveset.ability = section[4].text.gsub(/\n/m, '').gsub(/\t/m, '').strip
52
- moveset.nature = section[6].text.gsub(/\n/m, '').gsub(/\t/m, '').strip
40
+ movesets = []
53
41
 
54
- section = smogon.xpath('//table[@class="info moveset"]/tr')[1].children
55
- moveset.moves = section[0].text.strip.gsub(/\n/, '').gsub(/~/, ',').gsub(/\s\s/, '')[2..-1]
56
- moveset.evs = section[2].text.strip
42
+ smogon.xpath('//table[@class="info strategyheader"]').each { |s|
43
+ moveset = Moveset.new
44
+
45
+ moveset.pokemon = smogon.xpath('//tr/td[@class="header"]/h1').last.text
46
+ moveset.name = s.xpath('tr')[1].xpath('td[@class="name"]/h2').first.text
47
+ moveset.tier = smogon.xpath('//div[@id="content_wrapper"]/ul/li/strong').last.text
48
+
49
+ s.xpath('.//a').each { |a|
50
+ (moveset.item ||= []) << a.text if a['href'].include? '/items/'
51
+ (moveset.ability ||= []) << a.text if a['href'].include? '/abilities/'
52
+ (moveset.nature ||= []) << a.text if a['href'].include? '/natures/'
53
+ }
54
+
55
+ movesets << moveset
56
+ }
57
57
 
58
- return moveset
58
+ i = 0
59
+ smogon.xpath('//table[@class="info moveset"]').each { |s|
60
+ moveset = movesets[i]
61
+
62
+ continue = false
63
+ s.xpath('.//td')[0].text.each_line { |a|
64
+ a = a.gsub(/\n?/, '').strip
65
+ if a == ?~
66
+ continue = false
67
+ elsif a == ?/
68
+ continue = true
69
+ elsif a.empty?
70
+ next
71
+ elsif a != ?~ && a != ?/
72
+ if continue
73
+ moveset.moves.last << a
74
+ else
75
+ (moveset.moves ||= []) << [a]
76
+ end
77
+ continue = false
78
+ end
79
+ }
80
+
81
+ moveset.evs = s.xpath('.//td').last.text.strip
82
+
83
+ movesets[i] = moveset
84
+ i += 1
85
+ }
86
+
87
+ return movesets
59
88
  end
60
89
  end
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  #--
2
3
  # Copyright(C) 2013 Giovanni Capuano <webmaster@giovannicapuano.net>
3
4
  #
@@ -21,7 +22,7 @@ class Moveset
21
22
  attr_accessor :pokemon, :name, :tier, :item, :ability, :nature, :moves, :evs
22
23
 
23
24
  def to_s
24
- "Name: #{pokemon}\nSet: #{name}\nTier: #{tier}\nItem: #{item}\nAbility: #{ability}\nNature: #{nature}\nMoves: #{moves}\nEVs: #{evs}"
25
+ "Item: #{item.join(' / ')}\nAbility: #{ability.join(' / ')}\nNature: #{nature.join(' / ')}\nMoves: #{''.tap { |s| moves.each { |move| s << move.join(' / ') + ', '}}[0..-3]}\nEVs: #{evs}"
25
26
  end
26
27
 
27
28
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Botemon
22
22
  def self.version
23
- '0.2.4'
23
+ '0.3'
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: botemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-10 00:00:00.000000000 Z
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cinch