For updates and announcements, follow @sferik.
Install the gem and add to the application’s Gemfile:
bundle add mlb
Or, if Bundler is not being used to manage dependencies:
gem install mlb
require "mlb"
mets = MLB::Teams.all(season: 2024).last
mets.name # => "New York Mets"
mets.short_name # => "NY Mets"
mets.abbreviation # => "NYM"
mets.league.name # => "National League"
mets.spring_league.name # => "Grapefruit League"
mets.division.name # => "National League East"
mets.first_year_of_play # => 1962
mets.location_name # => "Flushing"
mets.venue.name # => "Citi Field"
adam = MLB::Players.find(mets.roster.first.player)
adam.full_name # => "Adam Ottavino"
adam.primary_number # => 0
adam.primary_position.name # => "Pitcher"
adam.pitch_hand.description # => "Right"
adam.bat_side.description # => "Switch"
adam.current_age # => 38
adam.birth_date.to_s # => "1985-11-22"
adam.birth_city # => "New York"
adam.birth_state_province # => "NY"
adam.birth_country # => "USA"
adam.draft_year # => 2006
adam.mlb_debut_date.to_s # => "2010-05-29"
adam.height # => "6' 5\""
adam.weight # => 246
adam.active? # => true
By contributing to the project, you help:
⭐️ Bonus: Sponsors will get priority support and influence over the project roadmap. We will also list your name or your company’s logo on our GitHub page.
Building and maintaining an open-source project like this takes a considerable amount of time and effort. Your sponsorship can help sustain this project. Even a small monthly donation makes a huge difference!
Click here to sponsor this project.
Many of the MLB Stats API endpoints have not yet been implemented in this library. You can contribute to this library by implementing one or more of these endpoinds. If you are financially unable to sponsor this project, you can contribute code instead.
Checkout and repo:
git checkout git@github.com:sferik/mlb-ruby.git
Enter the repo’s directory:
cd mlb-ruby
Install dependencies via Bundler:
bin/setup
Run the default Rake task to ensure all tests pass:
bundle exec rake
Create a new branch for your feature or bug fix:
git checkout -b my-new-branch
Bug reports and pull requests are welcome on GitHub at https://github.com/sferik/mlb-ruby.
Pull requests will only be accepted if they meet all the following criteria:
Code must conform to Standard Ruby. This can be verified with:
bundle exec rake standard
Code must conform to the RuboCop rules. This can be verified with:
bundle exec rake rubocop
100% C0 code coverage. This can be verified with:
bundle exec rake test
100% mutation coverage. This can be verified with:
bundle exec rake mutant
The gem is available as open source under the terms of the MIT License.