Class: PoorPokemon::Pokedex

Inherits:
Object
  • Object
show all
Defined in:
lib/poor-pokemon/pokedex.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePokedex

Returns a new instance of Pokedex.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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

Instance Attribute Details

#pokeListObject

Returns the value of attribute pokeList.



2
3
4
# File 'lib/poor-pokemon/pokedex.rb', line 2

def pokeList
  @pokeList
end

Instance Method Details

#bestSix(flag = false) ⇒ Object



21
22
23
24
# 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) ⇒ Object



26
27
28
29
30
31
32
33
# 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) ⇒ Object



35
36
37
# File 'lib/poor-pokemon/pokedex.rb', line 35

def searchName(word)
  @pokeList.select{|pokemon| pokemon.name[word]} 
end