PokéPaste Ruby
Ruby parser for PokéPaste, the format used by Pokémon Showdown and various teambuilders.
Installation
Install with RubyGems:
gem install pokepaste
If using in your application, include in your Gemfile:
gem "pokepaste"
or your .gemspec:
Gem::Specification.new do |gem|
# ...
gem.add_runtime_dependency "pokepaste"
end
Usage
To parse a PokéPaste:
# From a string
team = PokePaste::parse(str)
# From pokepast.es
team = PokePaste::fetch("https://pokepast.es/5c46f9ec443664cb")
team = PokePaste::fetch("5c46f9ec443664cb") # full URL optional
Once you have it parsed, you have an instance of PokePaste::Team, an
Enumerable containing an instance of PokePaste::Pokemon for each Pokémon on
the team. You can loop over the team as with any Enumerable, and access the
data like so:
team.each do |pkmn|
pkmn.species # required
pkmn.nickname # default null
pkmn.gender # default null
pkmn.item # default null
# EVs and IVs are hashes with the stat as the key
# (:hp, :atk, :def, :spa, :spd, or :spe)
pkmn.evs[:hp] # default 0
pkmn.ivs[:spa] # default 31
pkmn.shiny? # default is false
pkmn.ability # default is null
pkmn.level # default is 50
pkmn.happiness # default is 255
pkmn.nature # default is :hardy (neutral nature)
# Moves are an array with the names of the moves as strings. If more than
# one move is specified for a slot, they will be put into an array
pkmn.moves # default is []
end
You can edit any of these properties, and process back into PokéPaste format
with #to_s:
paste = team.to_s
single_pokemon = team[3].to_s
To make a new paste, you can initialize a new PokePaste::Team and populate
it like so:
team = PokePaste::Team.new
team << PokePaste::Pokemon.new(
species: "Bulbasaur",
nickname: "Bud",
ivs: {atk: 0},
moves: %w[Tackle Growl]
)
puts team # prints the paste
And I suppose if you wanted to use this library just to fetch the raw text from a paste on pokepast.es, you could:
raw_paste = PokePaste.fetch(url_or_id).to_s
License
This library is released under the MIT license. See the
LICENSE.md
file included with this code or
the official page on OSI for more information.