GithubHelp home page GithubHelp logo

pokepaste-ruby's Introduction

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

These methods return 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 nil
  pkmn.gender # default nil
  pkmn.item # default nil

  # 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 nil
  pkmn.tera_type # default is nil
  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},
  shiny: true,
  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

This library is purely a parser for the PokéPaste format, it does not contain any data about the Pokémon, whether or not the moves are valid, their abilities, anything like that. You could enter nonsense into any of the given fields and they will be parsed to and from the PokéPaste format happily. Validating anything beyond the syntax of the PokéPaste is left up to the user.

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.

I am not affiliated with Nintendo, Game Freak, The Pokémon Company, or any of their subsidiaries. This is a free fan-made project. Pokémon is © and ™ Nintendo.

pokepaste-ruby's People

Contributors

vinnydiehl avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.