title: How to Read and Convert from Standard Input text data to Structured Data in Ruby?
body: <p>I want to parse stdin text, and fetch to structured data container object.
  I confuse every time and finally I use global variables, ARGF, each and split.
  How can I do this better? How can I write easier and read easier? Or what gem does help me?</p>
  
  <p>Below is one case of my ugly code:</p>
  
  <pre><code># encoding: utf-8
  $DATA = {}
  $COUNT = 0
  
  ARGF.each do |line|
    col = line.split(nil).map(&amp;:to_i)
    if col.count == 1
      next
    elsif col.count == 2
      $DATA[$COUNT][:cut_param] &lt;&lt; { :cut_order =&gt; col[0], :pick_count =&gt; col[1] }
    elsif col.count == 3
      $COUNT += 1
      $DATA[$COUNT] = {
        :card_amount  =&gt; col[0],
        :cut_count    =&gt; col[1],
        :needle_order =&gt; col[2],
        :cut_param    =&gt; []
      }
    end
  end
  </code></pre>