<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.vanhecke.info/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>Written along the rails</title>
	
	<link>http://ruby.vanhecke.info</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 14 Nov 2011 21:44:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.vanhecke.info/RubyNotes" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="rubynotes" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Managing several Ruby versions and Gem collections on Windows with Pik</title>
		<link>http://ruby.vanhecke.info/2011/04/12/managing-several-ruby-versions-and-gem-collections-on-windows-with-pik/</link>
		<comments>http://ruby.vanhecke.info/2011/04/12/managing-several-ruby-versions-and-gem-collections-on-windows-with-pik/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 14:25:45 +0000</pubDate>
		<dc:creator>Pascal Van Hecke</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[pik]]></category>
		<category><![CDATA[renaming]]></category>
		<category><![CDATA[ruby version manager]]></category>
		<category><![CDATA[versioning]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://ruby.vanhecke.info/?p=10</guid>
		<description><![CDATA[If you have several versions and releases of Ruby (e.g. 187-p330, –p334, 1.9.2…) each with their own set of collections of gems for a specific app, then Pik becomes a bit cumbersome to select and manage your Ruby versions – there’s no command to “rename” a Ruby version to a for you memorable name (such [...]]]></description>
			<content:encoded><![CDATA[<p>If you have several versions and releases of Ruby (e.g. 187-p330, –p334, 1.9.2…) each with their own set of collections of gems for a specific app, then Pik becomes a bit cumbersome to select and manage your Ruby versions – there’s no command to “rename” a Ruby version to a for you memorable name (such as the name for the application linked to the ruby install).</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:d06ec78b-6b57-4834-a4d9-75dac8cd6bd7" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 508px; height: 257px;" style=" width: 508px; height: 257px;overflow: auto;">  $ pik list

  186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
  187-ref-r187-p330: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
* 187: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
  187: ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
  192-192-rubies-refinery: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
  192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>Now there’s also a way to do that manually: just edit the config.yml file in your C:\Users\Pascal\.pik\ folder:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:336abb98-cdf5-4613-870c-ec744ce3e09d" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 508px; height: 257px;" style=" width: 508px; height: 257px;overflow: auto;">---
&quot;186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Ruby/bin
&quot;187-ref-r187-p330: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-187-p330/bin
&quot;187: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/ruby187/bin
&quot;187: ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-187-p334/bin
&quot;192-192-rubies-refinery: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-192-p180/bin
&quot;192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Ruby192/bin
--- {}</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>
  <br />Becomes (by changing the “logical names” before the colon to something more meaningful):</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:e4eff62d-016b-44a8-ab44-6703def8379e" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 508px; height: 257px;" style=" width: 508px; height: 257px;overflow: auto;">---
&quot;Default-186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Ruby/bin
&quot;RefineryGemset-187-p330: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-187-p330/bin
&quot;Default-187: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/ruby187/bin
&quot;Clean-187: ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-187-p334/bin
&quot;RefineryGemset-192-p189: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-192-p180/bin
&quot;Default-192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Ruby192/bin
--- {}
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>And now listing and selecting (with Pik use…) the right version is a lot easier:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:c209a943-ee41-4971-90d6-4a0cacd47d3b" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 508px; height: 257px;" style=" width: 508px; height: 257px;overflow: auto;">  $ pik list
  Clean-187: ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
  Default-186: ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
* Default-187: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
  Default-192: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
  RefineryGemset-187-p330: ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
  RefineryGemset-192-p189: ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>What you can also do now, is manually copying a base Ruby+gems collections when you start a new app, e.g. copy C:\Users\Pascal\.pik\rubies\Ruby-187-p334 to C:\Users\Pascal\.pik\rubies\Ruby-187-p334-Refinery and add in the config.yml: </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:dfbe7df5-1e25-4997-b237-25192fe00b88" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 534px; height: 108px;" style=" width: 534px; height: 108px;overflow: auto;">&quot;Newapp-187: ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]&quot;:
  :path: !ruby/object:Pathname
    path: C:/Users/Pascal/.pik/rubies/Ruby-187-p334-Refinery/bin</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<blockquote>
<p>BTW: don’t forget to also add the path to the new Ruby version to your Devkit/config.yml file and to run ruby dk.rb install if you want to use native extensions.</p>
</blockquote>
<img src="http://feeds.feedburner.com/~r/RubyNotes/~4/eG7RrGU8Dqg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://ruby.vanhecke.info/2011/04/12/managing-several-ruby-versions-and-gem-collections-on-windows-with-pik/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>“Pik install” command downloads and extracts a Ruby version, but: “Couldn’t find a Ruby version at &lt;path&gt;”</title>
		<link>http://ruby.vanhecke.info/2011/04/12/pik-install-command-downloads-and-extracts-a-ruby-version-but-couldnt-find-a-ruby-version-at-path/</link>
		<comments>http://ruby.vanhecke.info/2011/04/12/pik-install-command-downloads-and-extracts-a-ruby-version-but-couldnt-find-a-ruby-version-at-path/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 14:11:04 +0000</pubDate>
		<dc:creator>Pascal Van Hecke</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[pik]]></category>
		<category><![CDATA[ruby version manager]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://ruby.vanhecke.info/2011/04/12/pik-install-command-downloads-and-extracts-a-ruby-version-but-couldnt-find-a-ruby-version-at-path/</guid>
		<description><![CDATA[I had this issue several times up to the point I was unable to install any Ruby version.&#160; Then I went looking in the C:\Users\Pascal\.pik\downloads]]></description>
			<content:encoded><![CDATA[<p>I had this issue several times up to the point I was unable to install any Ruby version.&#160; Then I went looking in the </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:a8a30421-a899-4c66-a7d2-5941d53fef21" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 55px;" style=" width: 400px; height: 55px;overflow: auto;">C:\Users\Pascal\.pik\downloads</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>directory and found several .7x files with file size = 0 from failed previous installs.</p>
<p>Delete those, and you’re able to install the corresponding Ruby versions again…</p>
<img src="http://feeds.feedburner.com/~r/RubyNotes/~4/O_M8mZwvGF4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://ruby.vanhecke.info/2011/04/12/pik-install-command-downloads-and-extracts-a-ruby-version-but-couldnt-find-a-ruby-version-at-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sh.exe “command not found” for an installed gem (while using pik and msysgit on Windows)</title>
		<link>http://ruby.vanhecke.info/2011/03/16/sh-exe-command-not-found-for-an-installed-gem-while-using-pik-and-msysgit-on-windows/</link>
		<comments>http://ruby.vanhecke.info/2011/03/16/sh-exe-command-not-found-for-an-installed-gem-while-using-pik-and-msysgit-on-windows/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 17:22:36 +0000</pubDate>
		<dc:creator>Pascal Van Hecke</dc:creator>
				<category><![CDATA[Infrastructure]]></category>
		<category><![CDATA[bundler]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[msysgit]]></category>
		<category><![CDATA[pik]]></category>
		<category><![CDATA[ruby version manager]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://ruby.vanhecke.info/2011/03/16/sh-exe-command-not-found-for-an-installed-gem-while-using-pik-and-msysgit-on-windows/</guid>
		<description><![CDATA[Just for the people googling this problem…&#160; If you have installed a gem and the promised command does not work (in my case: “annotate” after installing the Annotate gem), try: bundle exec annotate]]></description>
			<content:encoded><![CDATA[<p>Just for the people googling this problem…&#160; If you have installed a gem and the promised command does not work (in my case: “annotate” after installing the <a href="https://github.com/ctran/annotate_models" target="_blank">Annotate gem</a>), try:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:52d18e6e-fd71-4c2b-a9fe-2b21b2597d77" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 40px;" style=" width: 400px; height: 40px;overflow: auto;">bundle exec annotate
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>That way, you force a lookup in the bundled gems rather than the system gems.</p>
<img src="http://feeds.feedburner.com/~r/RubyNotes/~4/xjNLNMJbtj4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://ruby.vanhecke.info/2011/03/16/sh-exe-command-not-found-for-an-installed-gem-while-using-pik-and-msysgit-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Rails for Batch processes (example: Moneybird export via API and command-line)</title>
		<link>http://ruby.vanhecke.info/2011/03/02/using-rails-for-batch-processes-example-moneybird-export-via-api-and-command-line/</link>
		<comments>http://ruby.vanhecke.info/2011/03/02/using-rails-for-batch-processes-example-moneybird-export-via-api-and-command-line/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 15:03:32 +0000</pubDate>
		<dc:creator>Pascal Van Hecke</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Language]]></category>

		<guid isPermaLink="false">http://ruby.vanhecke.info/?p=7</guid>
		<description><![CDATA[My accountant needs to have my financial data in a somewhat slightly different format than the export my online invoicing application provides. Luckily Moneybird has an api so I set out to write my alternative export.&#160; I googled around for some best practices, and this is the workflow I came up with: Create a new [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>My accountant needs to have my financial data in a somewhat slightly different format than the export my <a href="http://www.moneybird.nl/?referrer=t8h5cwlj" target="_blank">online invoicing application</a> provides. Luckily <a href="http://www.moneybird.nl/?referrer=t8h5cwlj" target="_blank">Moneybird</a> has an <a href="http://www.moneybird.nl/api" target="_blank">api</a> so I set out to write my alternative export.&#160; I googled around for some best practices, and this is the workflow I came up with:</p>
<h3>Create a new Rails app</h3>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:f409cac3-0230-4d7f-94e7-5086c2d67c62" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 60px;" style=" width: 400px; height: 60px;overflow: auto;">&gt; rails new moneybirdexport
&gt; cd moneybirdexport
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<h3>Generate models for api access and conversion logic</h3>
<p>Our goal is a list of incoming and outgoing invoices – so we generate models with the required fields.</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:dd0d89c7-bd2d-4816-a646-bba46f5bc00a" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 80px;" style=" width: 400px; height: 80px;overflow: auto;">&gt; rails generate model dumped_invoice klant:string, factuurdatum:date, periode:string, factuurnummer:string, bedrag_excl_btw:decimal, btw_percentage:decimal, bedrag_incl_btw:decimal, omschrijving:text, soort:string, betaald:string, datum:date, betaalwijze:string
&gt; rails generate model dumped_incoming_invoice factuurdatum:date, periode:string, factuurnummer:string, bedrag_excl_btw:decimal, btw_bedrag:decimal, bedrag_incl_btw:decimal, omschrijving:text, soort:string, betaald:string, datum:date, betaalwijze:string
&gt; rake db:migrate</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>The Moneybird API exposes invoice, incoming_invoice and contact. No need to use a generator here, create the app/models/ files contact.rb, incoming_invoice.rb, and invoice.rb, to create the ActiveResources Contact, IncomingInvoice and Invoice – the source is identical apart from the classnames:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:567394aa-dc4c-48d0-ae69-74ba523d765f" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 130px;" style=" width: 400px; height: 130px;overflow: auto;">class Invoice &lt; ActiveResource::Base
  self.site         = &quot;https://&quot; + Moneybirdexport::MBX_ACCOUNT_NAME + &quot;.moneybird.com&quot;
  self.user         = Moneybirdexport::MBX_USER_NAME
  self.password     = Moneybirdexport::MBX_PASSWORD
  self.timeout = 5
end
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Not sure what the best practice is here, but I put per-app configurable values in config/application.rb, so if you use the constant values in the same way I did in the previous lines, you need to define them there as well:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:58e27370-46ad-491a-b80e-c7d02fb6c0df" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 200px;" style=" width: 400px; height: 200px;overflow: auto;">module Moneybirdexport
  class Application &lt; Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # ...
  end

  MBX_ACCOUNT_NAME  = &quot;username&quot;
  MBX_USER_NAME     = &quot;someemailaddress@domain.com&quot;
  MBX_PASSWORD      = &quot;secret&quot;
end</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>You should be able to test the api already on the command-line (YAML::dump gives a well-formatted output of objects):</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:34cd3e74-a7dd-4c28-bc82-a44868c05b88" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 80px;" style=" width: 400px; height: 80px;overflow: auto;">&gt; rails console
irb(main):&gt; puts YAML::dump Invoice.first
irb(main):&gt; puts YAML::dump IncomingInvoice.first
irb(main):&gt; puts YAML::dump Contact.first</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<h3>Write the conversion logic</h3>
<p>Some fields I need for my export (dumped_invoices and dumped_incoming_invoices) are not attributes of Invoices and IncomingInvoices as Moneybird sees them.&#160; So in the models DumpedInvoice and DumpedIncomingInvoice there’s a method <em>set_attributes_from_invoice</em> that digs out the info from somewhat deeper in the Moneybird model (looks up the related contact name, or fabricates a description from the invoice line items’ description…).&#160; Exactly how this is done is not important, I’m just copy-pasting my code here if you need to do something similar with the Moneybird API:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:e88b0165-e7e3-43b8-b717-d0202f9f7f2d" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 100px;" style=" width: 400px; height: 100px;overflow: auto;">class DumpedInvoice &lt; ActiveRecord::Base

  # need to include ActionView::helper because I am using the truncate method
  # source: http://stackoverflow.com/questions/489641/using-helpers-in-model-how-do-i-include-helper-dependencies
  include ActionView::Helpers

  def set_attributes_from_invoice(i) # i should be an Invoice ActiveResource
    self.klant            = i.company_name
    self.factuurdatum     = i.invoice_date
    self.periode          = ((i.invoice_date.month + 2)/3).to_s + &quot;e kw&quot;
    self.factuurnummer    = i.invoice_id
    self.bedrag_excl_btw  = i.total_price_excl_tax
    self.bedrag_incl_btw  = i.total_price_incl_tax 

    self.btw_percentage   = 0  if ( self.bedrag_excl_btw == 0)
    self.btw_percentage   = ((self.bedrag_incl_btw - self.bedrag_excl_btw + 0.001)/ self.bedrag_excl_btw * 100).to_i if ( self.bedrag_excl_btw &gt;0) 

    # concatenate the detail description and remove tabs, linebreaks with squish
    concat_details_descr  = i.details.map(&amp;:description).join(&quot; - &quot;).squish
    self.omschrijving     = truncate(sanitize(concat_details_descr), :length=&gt; 100)

    self.betaald          = &quot;Ja&quot; # shortcut - all of them paid by now...
    self.datum            = i.payments.last.payment_date # shortcut - everything was just one payment...
    self.betaalwijze      = i.payments.last.payment_method
    return self
  end

end</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:14372dcc-273f-4036-bf1c-0d72072a24e0" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 100px;" style=" width: 400px; height: 100px;overflow: auto;">class DumpedIncomingInvoice &lt; ActiveRecord::Base

  # need to include ActionView::helper because I am using the truncate method
  # source: http://stackoverflow.com/questions/489641/using-helpers-in-model-how-do-i-include-helper-dependencies
  include ActionView::Helpers

  def set_attributes_from_invoice(i) # i should be an IncomingInvoice ActiveResource
    self.factuurdatum     = i.invoice_date
    self.periode          = ((i.invoice_date.month + 2)/3).to_s + &quot;e kw&quot;
    self.factuurnummer    = i.invoice_id
    self.bedrag_excl_btw  = i.price_incl_tax - i.price_tax
    self.btw_bedrag       = i.price_tax
    self.bedrag_incl_btw  = i.price_incl_tax

    invoice_company       = Contact.find(i.contact_id)
    self.omschrijving     = invoice_company.company_name

    self.betaald          = &quot;Ja&quot; # shortcut - ze zijn idd allemaal betaald...
    self.datum            = i.payments.last.payment_date # shortcut - everything was just one payment...
    self.betaalwijze      = i.payments.last.payment_method
    return self
  end

end</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>(If this was actual code for an app, I would of course factor out the duplication… <img src='http://ruby.vanhecke.info/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  )</p>
<h3>Define the actual Batch script as a Rake task</h3>
<p>There are several ways to load the Rails libraries, but using a Rake task is probably <a href="http://stackoverflow.com/questions/529651/how-can-i-set-the-rails-environment-for-my-somewhat-stand-alone-ruby-script" target="_blank">the best solution</a> and there’s an <a href="http://railscasts.com/episodes/66-custom-rake-tasks" target="_blank">excellent railscast on Rake</a>. I use the <a href="http://fastercsv.rubyforge.org/" target="_blank">FasterCSV library</a> here because I couldn’t figure out quickly how to use tabs instead of commas as separators with the built-in CSV library.&#160; Don’t forget to include <em>gem &quot;fastercsv&quot;</em> in your Gemfile and run <em>bundle install</em> if you do as well.&#160; I followed the Railscast tutorial step by step to come up with a lib/tasks/export.rake that accepts an optional year parameter so you can run:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:d3bb894b-df67-4e00-bac6-5f38d8fc54b7" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 70px;" style=" width: 400px; height: 70px;overflow: auto;">rake export:invoices
rake export:incoming_invoices year=2011
rake export:all</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:f2898c07-0a35-4b7e-8d57-fbb5e4d1c2f9" class="wlWriterEditableSmartContent">
<pre class="brush: ruby; gutter: false; first-line: 1; tab-size: 4;  toolbar: false;  width: 400px; height: 400px;" style=" width: 400px; height: 400px;overflow: auto;">namespace :export do

  # Note: you need to add :environment as dependency so the rake &quot;environment&quot;
  # task is called that loads the enviromennt

  desc &quot;exports invoices&quot;
  task :invoices =&gt; :environment  do      

    param_year = ENV[&quot;year&quot;].to_i
    param_year = 2010 if param_year == 0

    # make sure you have included &quot;gem 'fastercsv'&quot; in your Gemfile and run &quot;bundle install&quot;
    # needs to be tab-separated because data contains commas...
    FasterCSV.open(&quot;dumped_invoices.csv&quot;, 'wb', :col_sep =&gt; &quot;\t&quot;) do |csv|
      # write the columns headers
      csv &lt;&lt; DumpedInvoice.new.attributes.keys
      #iterate over invoices
      Invoice.all.select{|i| i.invoice_date.year == param_year}.sort_by(&amp;:invoice_date).each do |i|
        csv &lt;&lt;  DumpedInvoice.new.set_attributes_from_invoice(i).attributes.values
      end

    end
  end

  desc &quot;exports incoming invoices&quot;
  task :incoming_invoices =&gt; :environment  do      

    param_year = ENV[&quot;year&quot;].to_i
    param_year = 2010 if param_year == 0

    # make sure you have included &quot;gem 'fastercsv'&quot; in your Gemfile and run &quot;bundle install&quot;
    # needs to be tab-separated because data contains commas...
    FasterCSV.open(&quot;dumped_incoming_invoices.csv&quot;, 'wb', :col_sep =&gt; &quot;\t&quot;) do |csv|
      # write the columns headers
      csv &lt;&lt; DumpedIncomingInvoice.new.attributes.keys
      #iterate over invoices
      IncomingInvoice.all.select{|i| i.invoice_date.year == param_year}.sort_by(&amp;:invoice_date).each do |i|
        csv &lt;&lt;  DumpedIncomingInvoice.new.set_attributes_from_invoice(i).attributes.values
      end
    end
  end

  task :all =&gt; [:invoices, :incoming_invoices]

end
</pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</p>
<p>That’s it!&#160; My first blogpost since I started studying Ruby and Rails again after some dabbling with it <a href="http://ruby.vanhecke.info/2006/10/08/installing-a-gem-from-a-local-file/" target="_blank">back</a> <a href="http://ruby.vanhecke.info/2006/11/07/getting-an-objects-methods-without-the-inherited-methods/" target="_blank">in 2006</a>!</p>
<img src="http://feeds.feedburner.com/~r/RubyNotes/~4/W1x57M4Ul8A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://ruby.vanhecke.info/2011/03/02/using-rails-for-batch-processes-example-moneybird-export-via-api-and-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting an object’s methods without the inherited methods</title>
		<link>http://ruby.vanhecke.info/2006/11/07/getting-an-objects-methods-without-the-inherited-methods/</link>
		<comments>http://ruby.vanhecke.info/2006/11/07/getting-an-objects-methods-without-the-inherited-methods/#comments</comments>
		<pubDate>Tue, 07 Nov 2006 20:49:27 +0000</pubDate>
		<dc:creator>Pascal Van Hecke</dc:creator>
				<category><![CDATA[Language]]></category>

		<guid isPermaLink="false">http://ruby.vanhecke.info/?p=5</guid>
		<description><![CDATA[test = SomeObject.new test.methods - test.class.superclass.new.methods Or is there a shorter, less convoluted way? Update November 12th: yes there seems to be&#8230; puts String.instance_methods(false) From the Ruby For Rails Book, page 254, paragraph 9.8.1&#8230;. But: String.instance_methods(false).size = 83 , whereas (test.methods &#8211; test.class.superclass.new.methods).size = 102 (with test a string object). &#62;&#62; puts (test.methods - test.class.superclass.new.methods [...]]]></description>
			<content:encoded><![CDATA[<p><code>test = SomeObject.new<br />
test.methods - test.class.superclass.new.methods</code></p>
<p>Or is there a shorter, less convoluted way?</p>
<p><strong>Update November 12th</strong>:  yes there seems to be&#8230;</p>
<p><code>puts String.instance_methods(false)</code></p>
<p>From the <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FRuby-Rails-Techniques-Developers%2Fdp%2F1932394699%2Fsr%3D1-1%2Fqid%3D1163340085%3Fie%3DUTF8%26s%3Dbooks&amp;tag=noteslinksand-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325">Ruby For Rails</a><img src="http://www.assoc-amazon.com/e/ir?t=noteslinksand-20&amp;l=ur2&amp;o=1" style="border-style: none ! important; margin: 0px" border="0" height="1" width="1" /> Book, page 254, paragraph 9.8.1&#8230;.</p>
<p>But: String.instance_methods(false).size = 83 , whereas (test.methods &#8211; test.class.superclass.new.methods).size = 102 (with test a string object).</p>
<p><code>&gt;&gt; puts (test.methods - test.class.superclass.new.methods - String.instance_methods(false)).sort<br />
&lt;<br />
&lt;=<br />
&gt;<br />
&gt;=<br />
all?<br />
any?<br />
between?<br />
collect<br />
detect<br />
each_with_index<br />
entries<br />
find<br />
find_all<br />
grep<br />
inject<br />
map<br />
max<br />
member?<br />
min<br />
partition<br />
reject<br />
select<br />
sort<br />
sort_by<br />
zip<br />
=&gt; nil<br />
&gt;&gt; exit</code></p>
<p>The difference seems to be the methods of the mixed in modules&#8230;</p>
<img src="http://feeds.feedburner.com/~r/RubyNotes/~4/vk7DEB6RFek" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://ruby.vanhecke.info/2006/11/07/getting-an-objects-methods-without-the-inherited-methods/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing a Gem from a local file</title>
		<link>http://ruby.vanhecke.info/2006/10/08/installing-a-gem-from-a-local-file/</link>
		<comments>http://ruby.vanhecke.info/2006/10/08/installing-a-gem-from-a-local-file/#comments</comments>
		<pubDate>Sun, 08 Oct 2006 12:27:48 +0000</pubDate>
		<dc:creator>Pascal Van Hecke</dc:creator>
				<category><![CDATA[Infrastructure]]></category>

		<guid isPermaLink="false">http://ruby.vanhecke.info/?p=4</guid>
		<description><![CDATA[What if you want to install a Gem that you did not find on Rubyforge &#8211; one that was mailed to you or that you have downloaded? Simple: just add the downloaded file name to the gem install command, instead of the name of the gem. For example, installing the &#8220;simple-rss&#8221; extension would be: with [...]]]></description>
			<content:encoded><![CDATA[<p>What if you want to install a Gem that you did not find on Rubyforge &#8211; one that was mailed to you or that you have downloaded?</p>
<p>Simple: just add the downloaded file name to the gem install command, instead of the name of the gem.  For example, installing the &#8220;simple-rss&#8221; extension would be:</p>
<ul>
<li>with the path included if the file is not in the directory where your command line is:<br />
<code>gem install D:\downloads\ruby_gems\simple-rss-1.1.gem</code></li>
<li>or without, if you change directory in your command line to where the file is<br />
<code>gem install simple-rss-1.1.gem</code></li>
</ul>
<p>Instead of just:<br />
<code>gem install simple-rss</code></p>
<p>This might seem evident to most of you, but it took me a while to figure out as <a href="http://rubyforge.org/">rubyforge.org</a> was down today and I had to rely on <a href="http://rubyforge.iasi.roedu.net/gems/">this mirror</a>.</p>
<img src="http://feeds.feedburner.com/~r/RubyNotes/~4/zGIYZLRgMPc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://ruby.vanhecke.info/2006/10/08/installing-a-gem-from-a-local-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

