<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -46,6 +46,8 @@ A simple, clean DSL for describing, writing, and parsing fixed-width text files.
     end
   end
   
+Supported types are: string, integer, date, float, money, and money_with_implied_decimal.
+  
 Then either feed it a nested struct with data values to create the file in the defined format:
 
   test_data = {</diff>
      <filename>README.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,7 @@ PROJ.name = 'slither'
 PROJ.authors = 'Ryan Wood'
 PROJ.email = 'ryan.wood@gmail.com'
 PROJ.url = 'http://github.com/ryanwood/slither'
-PROJ.version = '0.99.0'
+PROJ.version = '0.99.1'
 PROJ.exclude = %w(\.git .gitignore ^tasks \.eprj ^pkg)
 PROJ.readme_file = 'README.rdoc'
 </diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
 --- 
-:minor: 0
+:minor: 1
 :patch: 99
 :major: 0</diff>
      <filename>VERSION.yml</filename>
    </modified>
    <modified>
      <diff>@@ -20,13 +20,15 @@ class Slither
       &quot;A#{@length}&quot;
     end
        
-    def to_type(value)
+    def parse(value)
       case @type
         when :integer: value.to_i
-        when :float: value.to_f
+        when :float, :money: value.to_f
+        when :money_with_implied_decimal:
+          value.to_f / 100
         when :date:
-          if @options[:date_format]
-            Date.strptime(value, @options[:date_format])
+          if @options[:format]
+            Date.strptime(value, @options[:format])
           else
             Date.strptime(value)
           end
@@ -35,13 +37,15 @@ class Slither
     end
     
     def format(value)
-      pad(formatter % format_as_string(value))
+      pad(formatter % to_s(value))
+    rescue
+      puts &quot;Could not format column '#{@name}' as a '#{@type}' with formatter '#{formatter}' and value of '#{value}' (formatted: '#{to_s(value)}'). #{$!}&quot;
     end
        
     private
     
       def formatter
-        &quot;%#{aligner}#{sizer}#{typer}&quot;
+        &quot;%#{aligner}#{sizer}s&quot;
       end
           
       def aligner
@@ -52,14 +56,6 @@ class Slither
         (@type == :float &amp;&amp; @precision) ? @precision : @length
       end
       
-      def typer
-        case @type
-          when :integer: 'd'
-          when :float: 's'
-          else 's'
-        end
-      end
-      
       # Manually apply padding. sprintf only allows padding on numeric fields.
       def pad(value)
       	return value unless @padding == :zero
@@ -69,19 +65,34 @@ class Slither
       	value.gsub(space[0], '0' * space[0].size)
       end
       
-      def format_as_string(value)
+      def to_s(value)
         result = case @type
-          when :date:
-            if @options[:date_format]
-              value.strftime(@options[:date_format])
+          when :date:            
+            # If it's a DBI::Timestamp object, see if we can convert it to a Time object
+            unless value.respond_to?(:strftime)
+              value = value.to_time if value.respond_to?(:to_time)
+            end
+            if value.respond_to?(:strftime)        
+              if @options[:format]
+                value.strftime(@options[:format])
+              else
+                value.strftime
+              end
             else
-              value.strftime
+              value.to_s
             end
-          else value.to_s
+          when :float:
+            @options[:format] ? @options[:format] % value.to_f : value.to_f.to_s
+          when :money:
+            &quot;%.2f&quot; % value.to_f
+          when :money_with_implied_decimal:
+            &quot;%d&quot; % (value.to_f * 100)
+          else 
+            value.to_s
         end
         raise( 
           Slither::FormattedStringExceedsLengthError, 
-          &quot;The formatted value '#{result}' exceeds #{@length} chararacters, the allowable length of the '#{@name}' column.&quot;
+          &quot;The formatted value '#{result}' in column '#{@name}' exceeds the allowed length of #{@length} chararacters.&quot;
         ) if result.length &gt; @length
         result
       end</diff>
      <filename>lib/slither/column.rb</filename>
    </modified>
    <modified>
      <diff>@@ -50,7 +50,7 @@ class Slither
       line_data = line.unpack(unpacker)
       row = {}
       @columns.each_with_index do |c, i|
-        row[c.name] = c.to_type(line_data[i]) unless RESERVED_NAMES.include?(c.name)
+        row[c.name] = c.parse(line_data[i]) unless RESERVED_NAMES.include?(c.name)
       end
       row
     end</diff>
      <filename>lib/slither/section.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,6 +6,7 @@ class Slither
   class RequiredSectionNotFoundError &lt; StandardError; end
   class RequiredSectionEmptyError &lt; StandardError; end
   class FormattedStringExceedsLengthError &lt; StandardError; end
+  class ColumnMismatchError &lt; StandardError; end
   
   
   def self.define(name, options = {}, &amp;block)</diff>
      <filename>lib/slither/slither.rb</filename>
    </modified>
    <modified>
      <diff>@@ -60,73 +60,55 @@ describe Slither::Column do
   it &quot;should return the proper unpack value for a string&quot; do
     @column.send(:unpacker).should == 'A5'
   end
-  
-  describe &quot;when typing the value&quot; do
+    
+  describe &quot;when parsing a value from a file&quot; do    
     it &quot;should default to a string&quot; do
-      @column.to_type('name').should == 'name'
+      @column.parse('    name ').should == 'name'
+      @column.parse('      234').should == '234'
+      @column.parse('000000234').should == '000000234'
+      @column.parse('12.34').should == '12.34'
     end
-    
-    it &quot;should support the :integer type&quot; do
-      @column = Slither::Column.new(@name, @length, :type =&gt; :integer)
-      @column.to_type('234').should == 234
+  
+    it &quot;should support the integer type&quot; do
+      @column = Slither::Column.new(:amount, 10, :type=&gt; :integer)
+      @column.parse('234     ').should == 234
+      @column.parse('     234').should == 234
+      @column.parse('00000234').should == 234
+      @column.parse('Ryan    ').should == 0
+      @column.parse('00023.45').should == 23
     end
 
-    it &quot;should support the :float type&quot; do
-      @column = Slither::Column.new(@name, @length, :type =&gt; :float)
-      @column.to_type('234.45').should == 234.45
-    end
+    it &quot;should support the float type&quot; do
+      @column = Slither::Column.new(:amount, 10, :type=&gt; :float)
+      @column.parse('  234.45').should == 234.45
+      @column.parse('234.5600').should == 234.56
+      @column.parse('     234').should == 234.0
+      @column.parse('00000234').should == 234.0
+      @column.parse('Ryan    ').should == 0
+      @column.parse('00023.45').should == 23.45
+    end
+    
+    it &quot;should support the money_with_implied_decimal type&quot; do
+      @column = Slither::Column.new(:amount, 10, :type=&gt; :money_with_implied_decimal)
+      @column.parse('   23445').should == 234.45
+    end    
 
-    it &quot;should support the :date type&quot; do
-      @column = Slither::Column.new(@name, @length, :type =&gt; :date)
-      dt = @column.to_type('2009-08-22')
+    it &quot;should support the date type&quot; do
+      @column = Slither::Column.new(:date, 10, :type =&gt; :date)
+      dt = @column.parse('2009-08-22')
       dt.should be_a(Date)
       dt.to_s.should == '2009-08-22'
     end   
     
-    it &quot;should use the :date_format option with :date type if available&quot; do
-      @column = Slither::Column.new(@name, @length, :type =&gt; :date, :date_format =&gt; &quot;%m%d%Y&quot;)
-      dt = @column.to_type('08222009')
+    it &quot;should use the format option with date type if available&quot; do
+      @column = Slither::Column.new(:date, 10, :type =&gt; :date, :format =&gt; &quot;%m%d%Y&quot;)
+      dt = @column.parse('08222009')
       dt.should be_a(Date)
       dt.to_s.should == '2009-08-22'
     end   
   end
   
-  describe &quot;when getting the column's the value as a string&quot; do
-    it &quot;should default to a string&quot; do
-      @column.send(:format_as_string, 'name').should == 'name'
-    end
-    
-    it &quot;should raise an error if the value is longer than the length&quot; do
-      lambda { @column.send(:format_as_string, 'This string is too long') }.should raise_error(
-        Slither::FormattedStringExceedsLengthError, 
-        &quot;The formatted value 'This string is too long' exceeds #{@length} chararacters, the allowable length of the '#{@name}' column.&quot;
-      )
-    end
-    
-    it &quot;should support the :integer type&quot; do
-      @column = Slither::Column.new(@name, @length, :type =&gt; :integer)
-      @column.send(:format_as_string, 234).should == '234'
-    end
-
-    it &quot;should support the :float type&quot; do
-      @column = Slither::Column.new(:amount, 6, :type =&gt; :float)
-      @column.send(:format_as_string, 234.45).should == '234.45'
-    end
-
-    it &quot;should support the :date type&quot; do
-      dt = Date.new(2009, 8, 22)
-      @column = Slither::Column.new(:date, 10, :type =&gt; :date)
-      @column.send(:format_as_string, dt).should == '2009-08-22'
-    end   
-    
-    it &quot;should use the :date_format option with :date type if available&quot; do
-      dt = Date.new(2009, 8, 22)
-      @column = Slither::Column.new(:date, 8, :type =&gt; :date, :date_format =&gt; &quot;%m%d%Y&quot;)
-      @column.send(:format_as_string, dt).should == '08222009'
-    end 
-  end
-  
-  describe &quot;when formatting a column&quot; do
+  describe &quot;when applying formatting options&quot; do
     it &quot;should return a proper formatter&quot; do
       @column = Slither::Column.new(@name, @length, :align =&gt; :left)
       @column.send(:formatter).should == &quot;%-5s&quot;
@@ -162,6 +144,68 @@ describe Slither::Column do
         @column = Slither::Column.new(@name, @length, :type =&gt; :float, :padding =&gt; :zero, :align =&gt; :left)
         @column.format(4.45).should == '4.450'
       end
+    end    
+  end
+    
+  describe &quot;when formatting values for a file&quot; do
+    it &quot;should default to a string&quot; do
+      @column = Slither::Column.new(:name, 10)
+      @column.format('Bill').should == '      Bill'
+    end
+    
+    it &quot;should raise an error if the value is longer than the length&quot; do
+      @value = &quot;XX&quot; * @length
+      lambda { @column.format(@value) }.should raise_error(
+        Slither::FormattedStringExceedsLengthError, 
+        &quot;The formatted value '#{@value}' in column '#{@name}' exceeds the allowed length of #{@length} chararacters.&quot;
+      )
+    end
+    
+    it &quot;should support the integer type&quot; do
+      @column = Slither::Column.new(:amount, 10, :type =&gt; :integer)
+      @column.format(234).should        == '       234'
+      @column.format('234').should      == '       234'
     end
+  
+    it &quot;should support the float type&quot; do
+      @column = Slither::Column.new(:amount, 10, :type =&gt; :float)
+      @column.format(234.45).should       == '    234.45'
+      @column.format('234.4500').should   == '    234.45'
+      @column.format('3').should          == '       3.0'
+    end
+    
+    it &quot;should support the float type with a format&quot; do
+      @column = Slither::Column.new(:amount, 10, :type =&gt; :float, :format =&gt; &quot;%.3f&quot;)
+      @column.format(234.45).should       == '   234.450'
+      @column.format('234.4500').should   == '   234.450'
+      @column.format('3').should          == '     3.000'
+    end
+    
+    it &quot;should support the float type with a format, alignment and padding&quot; do
+      @column = Slither::Column.new(:amount, 10, :type =&gt; :float, :format =&gt; &quot;%.2f&quot;, :align =&gt; :left, :padding =&gt; :zero)
+      @column.format(234.45).should       == '234.450000'
+      @column = Slither::Column.new(:amount, 10, :type =&gt; :float, :format =&gt; &quot;%.2f&quot;, :align =&gt; :right, :padding =&gt; :zero)
+      @column.format('234.400').should    == '0000234.40'
+      @column = Slither::Column.new(:amount, 10, :type =&gt; :float, :format =&gt; &quot;%.4f&quot;, :align =&gt; :left, :padding =&gt; :space)
+      @column.format('3').should          == '3.0000    '
+    end
+    
+    it &quot;should support the money_with_implied_decimal type&quot; do
+      @column = Slither::Column.new(:amount, 10, :type=&gt; :money_with_implied_decimal)
+      @column.format(234.450).should   == &quot;     23445&quot;
+      @column.format(12.34).should     == &quot;      1234&quot;
+    end    
+  
+    it &quot;should support the date type&quot; do
+      dt = Date.new(2009, 8, 22)
+      @column = Slither::Column.new(:date, 10, :type =&gt; :date)
+      @column.format(dt).should == '2009-08-22'
+    end   
+    
+    it &quot;should support the date type with a :format&quot; do
+      dt = Date.new(2009, 8, 22)
+      @column = Slither::Column.new(:date, 8, :type =&gt; :date, :format =&gt; &quot;%m%d%Y&quot;)
+      @column.format(dt).should == '08222009'
+    end 
   end
 end
\ No newline at end of file</diff>
      <filename>spec/column_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -69,15 +69,6 @@ describe Slither::Parser do
       lambda { @parser.parse }.should raise_error(Slither::RequiredSectionNotFoundError, &quot;Required section 'header' was not found.&quot;)
     end
     
-    it &quot;raise an error if a section limit is over run&quot;
+    # it &quot;raise an error if a section limit is over run&quot;
   end
-  
-
-  
-  describe &quot;when in linear mode&quot; do
-
-  end
-  
-
-
 end
\ No newline at end of file</diff>
      <filename>spec/parser_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>37062d34979ad17a90452cffec67381097521a8a</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Wood</name>
    <email>ryan.wood@gmail.com</email>
  </author>
  <url>http://github.com/ryanwood/slither/commit/d9a85792b8e96090f571cde61dd2aae213d4a301</url>
  <id>d9a85792b8e96090f571cde61dd2aae213d4a301</id>
  <committed-date>2009-04-23T13:02:15-07:00</committed-date>
  <authored-date>2009-04-23T13:02:15-07:00</authored-date>
  <message>Added better support for float formatting and money_with_implied_decimal types</message>
  <tree>4a67a6397bf953608220863d88f8eacce939ecc6</tree>
  <committer>
    <name>Ryan Wood</name>
    <email>ryan.wood@gmail.com</email>
  </committer>
</commit>
