class PoorPokemon::Pokedex

Attributes

pokeList[RW]

Public Class Methods

new() click to toggle source
# File lib/poor-pokemon/pokedex.rb, line 3
def initialize
  # Pokemon database
  # http://pokedream.com/pokedex/pokemon?display=gen1
  pokemonDoc = Nokogiri::HTML(open("http://pokedream.com/pokedex/pokemon?display=gen1"))
  @pokeList = pokemonDoc.css(".UILinkedTableRow").map{ |row|
    rowData = row.children().map{ |col|
      if col.attribute("class")
        col.attribute("class").value
      else
        col.text()
      end
    }.reject{|val| val == "\n" || val == "---"}
    rowData
  }.map{|row|
    PoorPokemon::PokedexPokemon.new(row)
  }
end

Public Instance Methods

bestSix(flag=false) click to toggle source
# File lib/poor-pokemon/pokedex.rb, line 21
def bestSix(flag=false)
  #flag is for enemy to have perfect stats
  @pokeList.sort{|pokemonA,pokemonB| pokemonB.totalStats <=> pokemonA.totalStats}.take(6).map{|pokemon|pokemon.clone(flag)}
end
randSix(flag=false) click to toggle source
# File lib/poor-pokemon/pokedex.rb, line 26
def randSix(flag=false)
  #flag is for enemy to have perfect stats
  randArray = []
  6.times do
    randArray.push(@pokeList.sample.clone(flag))
  end
  randArray
end
searchName(word) click to toggle source
# File lib/poor-pokemon/pokedex.rb, line 35
def searchName(word)
  @pokeList.select{|pokemon| pokemon.name[word]} 
end