64 lines
2.5 KiB
Markdown
64 lines
2.5 KiB
Markdown
+++
|
|
date = "2008-08-14"
|
|
title = "Useless Ruby Gems for your pleasure"
|
|
tags = ["Blog", "Ruby on Rails"]
|
|
slug = "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.
|
|
|
|
<pre lang="ruby">class Player < ActiveRecord::Base
|
|
acts_as_gold :column => :money
|
|
end
|
|
|
|
# This will be store like @player.money => 2003652
|
|
@player.gold => 200
|
|
@player.silver => 36
|
|
@player.copper => 52
|
|
|
|
# You can also easily earn or spend money
|
|
@player.earn(10.gold + 75.silver)
|
|
@player.spend(1.gold + 10.silver + 95.copper)</pre>
|
|
|
|
<a href="http://github.com/ariejan/acts_as_gold/tree/master/README.textile">Read more about the Gem</a>, or install the gem right now:
|
|
|
|
<pre>sudo gem install ariejan-acts_as_gold --source http://gems.github.com</pre>
|
|
|
|
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:
|
|
|
|
<ul>
|
|
<li>Name of the character</li>
|
|
<li>Name of the characters guild</li>
|
|
<li>Level</li>
|
|
<li>Race</li>
|
|
<li>Class</li>
|
|
</ul>
|
|
|
|
It works for both EU and US warcraft servers.
|
|
|
|
<pre lang="ruby">require 'warcraft_armory'
|
|
|
|
character = WarcraftArmory.find(:eu, 'Aszune', 'Nosius')
|
|
|
|
character.race => "Human"
|
|
character.level => 15</pre>
|
|
|
|
Again, simply install the plugin and use it like any other gem or <a href="http://github.com/ariejan/warcraft_armory/tree/master/README.textile">read the README</a> first.
|
|
|
|
<pre>sudo gem install ariejan-warcraft_armory --source http://gems.github.com</pre>
|
|
|
|
Of course, these gems are released under the MIT license. The code is on Gitub (<a href="https://github.com/ariejan/acts_as_gold/tree">acts_as_gold</a>, <a href="https://github.com/ariejan/warcraft_armory/tree">warcraft_armory</a>) 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.
|
|
|