Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I played a bit with SpreadSheet library and your file and checked the class of <code>row[1]</code>:</p> <pre><code>irb&gt; sheet.each {|row| print row[1], ' ', row[1].class; puts } 866202F501 String 866201F000 String 866201G600 String 866201G800 String 8662026800.0 Float 866202H010 String ... </code></pre> <p>Gotcha! It chages! Some of values has type of Float, so when you call <code>to_s</code> on them (or ActiveRecord, if you don't), it adds <code>.0</code>. That is simply the behaviour of <code>to_s</code> method of <code>Float</code>: it always adds fractional part, even if it is zero. <strong>Database is not related here.</strong></p> <p>Probably there might be more elegant solution (somehow configure Spreadsheet lib, modify xls) but the fastest hack is: <strong>sees Float -> converts to int before converting to string</strong>.</p> <p>Compare:</p> <pre><code>irb&gt; sheet.each {|row| puts row[1].is_a?(Numeric) ? row[1].to_i.to_s : row[1] } 866202F501 866201F000 866201G600 866201G800 8662026800 866202H010 </code></pre> <p><s>So you can just add this check to your check of <code>.present?</code>, probably wrapping this into a function in order not to look so ugly.</s> Here I use <code>Numeric</code> instead of <code>Float</code>: it is base class for all numbers so in case you somehow get decimal or something else, it is also caught.</p> <p><strong>UPD:</strong> Here comes the code sample: you can replace your line with the following:</p> <pre><code>oem = row[1].is_a?(Numeric) ? row[1].to_i.to_s : row[1] if row[1].present? </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload