Class: PoorPokemon::Pokedex
- Inherits:
-
Object
- Object
- PoorPokemon::Pokedex
- Defined in:
- lib/poor-pokemon/pokedex.rb
Instance Attribute Summary collapse
-
#pokeList ⇒ Object
Returns the value of attribute pokeList.
Instance Method Summary collapse
- #bestSix(flag = false) ⇒ Object
-
#initialize ⇒ Pokedex
constructor
A new instance of Pokedex.
- #randSix(flag = false) ⇒ Object
- #searchName(word) ⇒ Object
Constructor Details
#initialize ⇒ Pokedex
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
#pokeList ⇒ Object
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 |