Class: Pokedex

Inherits:
Object
  • Object
show all
Defined in:
lib/botemon/pokedex.rb

Overview

-- Copyright(C) 2013 Giovanni Capuano [email protected]

This file is part of Botémon.

Botémon is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Botémon is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Botémon. If not, see http://www.gnu.org/licenses/. ++

Class Method Summary collapse

Class Method Details

.get(name, storage) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/botemon/pokedex.rb', line 29

def self.get(name, storage)
  return nil if name == nil
  
  if storage.is_cached?(name)
    return storage.get name
  else
    pokemon = Smogon::Pokedex.get name
    storage.add pokemon
    storage.save
    return pokemon
  end
end

.id2name(id) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/botemon/pokedex.rb', line 21

def self.id2name(id)
  begin
    return Nokogiri::HTML(open("http://pokemondb.net/pokedex/#{id}")).xpath('//div[@class="navbar"]/h1')[0].text
  rescue
    return nil
  end
end