Last updated

Useless Ruby Gems for your pleasure

The past few days I’v taken some time to find out how to create a Ruby Gem. This has been on my to-do list for quite a while, but now I’m able to tick it off.

Well, what did I make?

The first Gem can also be used as a Ruby on Rails plugin and is called ActsAsGold. If you’ve ever played World of Warcraft, you’ll know how the money system works. You have Copper. A 100 Copper is worth 1 Silver. And 100 Silver is worth 1 Gold.

The ActsAsGold Gem allows you to extend your ActiveRecord model with this money system. All you need on your model is an attribute that stores a single integer value.

Let me give you a small tour.

 1class Player < ActiveRecord::Base
 2  acts_as_gold :column => :money
 3end
 4
 5# This will be store like @player.money => 2003652
 6@player.gold => 200
 7@player.silver => 36
 8@player.copper => 52
 9
10# You can also easily earn or spend money
11@player.earn(10.gold + 75.silver)
12@player.spend(1.gold + 10.silver + 95.copper)

Read more about the Gem, or install the gem right now:

sudo gem install ariejan-acts_as_gold --source http://gems.github.com

The other gem is WarcraftArmory, which is still in early development, so new stuff can and will be added in the future.

WA (WarcraftArmory) allows you to easily retrieve character information from the World of Warcraft Armory. Currently it can retrieve:

  • Name of the character
  • Name of the characters guild
  • Level
  • Race
  • Class

It works for both EU and US warcraft servers.

1require 'warcraft_armory'
2
3character = WarcraftArmory.find(:eu, 'Aszune', 'Nosius')
4
5character.race => "Human"
6character.level => 15

Again, simply install the plugin and use it like any other gem or read the README first.

sudo gem install ariejan-warcraft_armory --source http://gems.github.com

Of course, these gems are released under the MIT license. The code is on Gitub (acts_as_gold, warcraft_armory) and patches with fixes and new features are gladly accepted.

Please let me know if you find these gems useful or if you use them in one of your projects.