<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>test/acts_as_gold_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,32 +1,45 @@
 h1. acts_as_gold
 
-Written by &quot;Ariejan de Vroom&quot;:mailto:ariejan@ariejan.net.
+Acts_as_gold extends ActiveRecord models to use a single integer column to store money in the form of Gold, Silver and Copper. This money system can be found in many games, including World of Warcraft.
+
+Written by &quot;Ariejan de Vroom&quot;:mailto:ariejan@ariejan.net
 
 Copyright 2008 Ariejan de Vroom
 
-h2. Download
+h2. Download and installation
+
+You can install acts_as_gold either as a Ruby on Rails plugin or a Ruby Gem. It's recommended you use the Ruby Gem to get easier updates later on. 
+
+h3. Plugin installation
+
+Simply install the plugin:
+
+&lt;pre&gt;./script/plugin install git://github.com/ariejan/acts_as_gold.git&lt;/pre&gt;
 
-Github: &quot;Page&quot;:http://github.com/ariejan/acts_as_gold/tree/master &quot;Clone&quot;:git://github.com/ariejan/acts_as_gold.git
+h3. Gem installation
 
-Gem: &lt;pre&gt;gem install ariejan-acts_as_gold --source http://gems.github.com&lt;/pre&gt;
+Just install the gem:
 
-Note: if you install acts_as_gold using the gem from Github, you'll need this
-in your environment.rb if you want to use Rails 2.1's dependency manager:
+&lt;pre&gt;gem install ariejan-acts_as_gold --source http://gems.github.com&lt;/pre&gt;
 
-config.gem &quot;ariejan-acts_as_gold&quot;,
+Add the following to your environment.rb if you want to use Rails 2.1's dependency manager (which is highly recommended):
+
+&lt;pre&gt;&lt;code&gt;config.gem &quot;ariejan-acts_as_gold&quot;,
            :lib    =&gt; &quot;acts_as_gold&quot;,
-           :source =&gt; &quot;http://gems.github.com&quot;
+           :source =&gt; &quot;http://gems.github.com&quot;&lt;/code&gt;&lt;/pre&gt;
 
 h2. Enabling acts_as_gold
 
-&lt;pre&gt;&lt;code&gt;# This will use player.money to store the current amount of money.
-class Player &lt; ActiveRecord::Base
-  acts_as_gold
-end
+This will use player.money to store the current amount of money.
+
+&lt;pre&gt;&lt;code&gt;class Player &lt; ActiveRecord::Base
+  acts_as_gold	# Uses the +money+ attribute from Player
+end&lt;/code&gt;&lt;/pre&gt;
+
+You may also specify a different column for storing money, for example +pennies+
 
-# You may also specify a different columnt for storing money
-class Player &lt; ActiveRecord::Base
-  acts_as_gold :current_value
+&lt;pre&gt;&lt;code&gt;class Player &lt; ActiveRecord::Base
+  acts_as_gold :column =&gt; :pennies # Uses the +pennies+ attribute from Player
 end&lt;/code&gt;&lt;/pre&gt;
 
 h2. Using acts_as_gold</diff>
      <filename>README.textile</filename>
    </modified>
    <modified>
      <diff>@@ -1,24 +1,23 @@
 Gem::Specification.new do |s|
   s.name = %q{acts_as_gold}
-  s.version = &quot;1.0.1&quot;
+  s.version = &quot;1.0.2&quot;
  
   s.specification_version = 2 if s.respond_to? :specification_version=
  
   s.required_rubygems_version = Gem::Requirement.new(&quot;&gt;= 0&quot;) if s.respond_to? :required_rubygems_version=
   s.authors = [&quot;Ariejan de Vroom&quot;]
+  s.homepage = %q{http://ariejan.net}
   s.date = %q{2008-08-13}
   s.description = %q{acts_as_gold allows you to extend a model with money in the form of Gold, Silver and Copper, as seen in World of Warcraft}
   s.email = %q{ariejan@ariejan.net}
   s.extra_rdoc_files = [&quot;README.textile&quot;]
-  s.files = [&quot;Changelog&quot;, &quot;LICENSE&quot;, &quot;Rakefile&quot;, &quot;README.textile&quot;, &quot;lib/acts_as_gold.rb&quot;, &quot;lib/active_record/acts/gold.rb&quot;]
+  s.files = [&quot;Changelog&quot;, &quot;LICENSE&quot;, &quot;Rakefile&quot;, &quot;README.textile&quot;, &quot;lib/acts_as_gold.rb&quot;, &quot;test/acts_as_gold_test.rb&quot;]
   s.has_rdoc = true
   s.rdoc_options = [&quot;--line-numbers&quot;, &quot;--inline-source&quot;, &quot;--main&quot;, &quot;README.textile&quot;]
   s.require_paths = [&quot;lib&quot;]
   s.rubygems_version = %q{1.0.1}
   s.summary = %q{acts_as_gold extends a model with Gold, Silver and Copper money.}
-  
-  # s.test_files = [&quot;test/attribute_proxy_test.rb&quot;, &quot;test/factory_test.rb&quot;, &quot;test/integration_test.rb&quot;, &quot;test/sequence_test.rb&quot;]
-  s.test_files = []
+  s.test_files = [&quot;test/acts_as_gold_test.rb&quot;]
   
   s.add_dependency(%q&lt;activerecord&gt;, [&quot;&gt;= 1.0&quot;])
 end
\ No newline at end of file</diff>
      <filename>acts_as_gold.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,3 @@
 $:.unshift &quot;#{File.dirname(__FILE__)}/lib&quot;
-require 'active_record/acts/gold'
-ActiveRecord::Base.class_eval { include ActiveRecord::Acts::Gold }
\ No newline at end of file
+require 'acts_as_gold'
+ActiveRecord::Base.class_eval { include ActsAsGold }
\ No newline at end of file</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1 +1,133 @@
-require 'active_record/acts/gold'
\ No newline at end of file
+module ActsAsGold
+  # Thrown when trying to spend more than you have.
+  class NotEnoughMoneyError &lt; StandardError
+  end
+  
+  def self.included(base)
+    base.extend(ClassMethods)
+  end
+
+  # This +acts_as+ extension provides the capabilities for splitting a given interger column into 
+  # three separte coin values: Copper, Silver and Gold. 
+  #
+  # A simple example: a Charachter has money ( t.integer :money, :limit =&gt; 20)
+  #
+  #   class Character &lt; ActiveRecord::Base
+  #     acts_as_gold                      # Uses the money attributes
+  #     acts_as_gold :column =&gt; :pennies  # Uses the pennies attributes
+  #   end
+  #
+  #   character.money   = 57503
+  #   character.gold    = 5
+  #   character.silver  = 75
+  #   character.copper  = 3
+  #
+  #   character.money  += 2.gold + 10.copper
+  #   character.gold   = 7
+  #   character.copper = 13
+  #   character.money  = 77513
+  #
+  # Copper and Silver have a maximum of 99. E.g. 100 copper =&gt; 1 silver and 100 silver =&gt; 1 Gold. 
+  # The maximum amount of money depends on the integer type used in the database:
+  #
+  # signed int(11)             2,147,483,647   =&gt;  214,748 Gold, 36 Silver, 47 Copper
+  # signed int(20) 9,223,372,036,854,775,807   =&gt;  922,337,203,685,477 Gold, ++8 Silver, 07 Copper
+  #
+  module ClassMethods
+    # Configuration options are:
+    #
+    # * +column+ - specifies the column name to use for keeping the money integer (default: +money+)
+    def acts_as_gold(options = {})
+      configuration = { :column =&gt; &quot;money&quot; }
+      configuration.update(options) if options.is_a?(Hash)
+
+      class_eval &lt;&lt;-EOV
+        include ActsAsGold::InstanceMethods
+        
+        def money_column
+          '#{configuration[:column]}'
+        end
+
+      EOV
+    end
+  end
+  
+  # Allow Fixnum and Bignum to easily convert to Gold, Silver or Copper. 
+  # This allows for things like:
+  #
+  # character.money = 2.gold + 45.silver + 50.copper
+  module IntegerExtensions
+    # 1.gold =&gt; 10000
+    def gold
+      self * 10000
+    end
+    
+    # 1.silver =&gt; 100
+    def silver
+      self * 100
+    end
+    
+    # Dummy, 1.copper =&gt; !
+    def copper
+      self
+    end
+  end
+
+  # All the methods available to records that have the acts_as_gold method enabled.
+  module InstanceMethods
+    # Earn money. 
+    #
+    # Either enter a total money value, or sum it up with gold and def silver. To earn
+    # 1 Gold, 95 silver and 0 copper you can do the following:
+    #
+    # character.earn(19500)
+    # character.earn(1.gold + 95.silver)
+    #
+    # This return true if the amount was added successfully
+    def earn(amount)
+      update_attribute(:money, money + amount)
+    end
+    
+    # Spend money
+    #
+    # You can specify money the same way as with earning money.
+    #
+    # We return true if the money was spend successfully.
+    #
+    # This will raise a 'ActiveRecord::Acts::Gold::NotEnoughMoneyError' when there's not enough money
+    def spend(amount)
+      if money &gt;= amount
+        update_attribute(:money, money - amount)
+      else
+        raise ActsAsGold::NotEnoughMoneyError
+      end
+    end
+    
+    # Return the amount of Gold
+    def gold
+      split_copper.first.divmod(100).first
+    end
+
+    def silver
+      split_copper.first.divmod(100).last
+    end
+    
+    def copper
+      split_copper.last
+    end
+
+    private
+    
+    def split_copper
+      self.send(money_column).divmod(100)
+    end
+  end 
+end
+
+class Fixnum
+  include ActsAsGold::IntegerExtensions
+end
+
+class Bignum
+  include ActsAsGold::IntegerExtensions
+end
\ No newline at end of file</diff>
      <filename>lib/acts_as_gold.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>lib/active_record/acts/gold.rb</filename>
    </removed>
    <removed>
      <filename>uninstall.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>ef267b4526e6a54cff2ba902c858956e00d5d289</id>
    </parent>
  </parents>
  <author>
    <name>Ariejan de Vroom</name>
    <email>ariejan@ariejan.net</email>
  </author>
  <url>http://github.com/ariejan/acts_as_gold/commit/7a3422044316134c7b0a5a7406e1ffdca5719bee</url>
  <id>7a3422044316134c7b0a5a7406e1ffdca5719bee</id>
  <committed-date>2008-08-13T04:18:21-07:00</committed-date>
  <authored-date>2008-08-13T04:18:21-07:00</authored-date>
  <message>[1.0.2] Added tests, some minor bugfixes.</message>
  <tree>0b4627e072387023662904a40b6cd2bde9ad74d0</tree>
  <committer>
    <name>Ariejan de Vroom</name>
    <email>ariejan@ariejan.net</email>
  </committer>
</commit>
