Technical
How To Get Data From Console And Splat It To Struct

  1. Get your data from console
    
    records = RegionAgreement.find_report_generation_progress_by_date
    => [#<RegionAgreement:0x41d5d6e4 @attributes={"region_name"=>"BLACKROCK", "region_id"=>6, "end_time"=>Wed Jul 11 07:01:00 -0400 2007, "start_time"=>Tue Jul 10 15:08:31 -0400 2007, "num_expected"=>122.0, "num_ready"=>122.0}>,...
    #This is a data that you need for your splats
    >> records.collect{|rec| rec.attributes.values}
    => [["BLACKROCK", 6, Wed Jul 11 07:01:00 -0400 2007, Tue Jul 10 15:08:31 -0400 2007, 122.0, 122.0],...
    
  2. Load data in to struct
    
      Record = Struct.new(:region_name, :region_id,:end_time,:start_time,:num_expected, :num_ready)
      def self.find_by_date_and_region_name
        #Your data 
        records = [
             ["BLACKROCK", 6, Wed Jul 11 07:01:00 -0400 2007, Tue Jul 10 15:08:31 -0400 2007, 122.0, 122.0],
             ["DTEWEB", 120, Wed Jul 11 09:05:42 -0400 2007, Wed Jul 11 06:08:29 -0400 2007, 191.0, 191.0],
             ["Frankfurt", 4, Wed Jul 11 07:01:00 -0400 2007, Tue Jul 10 14:08:04 -0400 2007, 579.0, 579.0]
          ]
    
      #This will return an array of struct objects that will be readable by rails in a view.    
      records.collect{|rec| Record.new(*rec)}
      #[<struct Record region_name="BLACKROCK", region_id=6, end_time=Wed Jul 11 07:01:00 -0400 2007, start_time=Tue Jul 10 15:08:31 -0400 2007, num_expected=122.0, num_ready=122.0>, 
      #<struct Record region_name="DTEWEB", region_id=120, end_time=Wed Jul 11 09:05:42 -0400 2007, start_time=Wed Jul 11 06:08:29 -0400 2007, num_expected=191.0, num_ready=191.0>, 
      #<struct Record region_name="Frankfurt", region_id=4, end_time=Wed Jul 11 07:01:00 -0400 2007, start_time=Tue Jul 10 14:08:04 -0400 2007, num_expected=579.0, num_ready=579.0>,..
    
    end 
    

Load data to Struct from CSV file


TradeRecord = Struct.new(:filter_id,:source_system_trade_id,:sentry_mtm,:sentry_val_date,:sentry_last_update,:cmdw_mtm,:cmdw_val_date,:cmdw_last_update)
File.open("test/fixtures/trade_rec.css").collect{|line| line.split(",")}.collect{|rec| TradeRecord.new(*rec)}

Your data would look like this…


[#<struct TradeRecord filter_id="5", source_system_trade_id="2", sentry_mtm="512", sentry_val_date="7/25/2007", sentry_last_update="7/25/2007 2:58:11 PM", cmdw_mtm="5127", cmdw_val_date="7/25/2007", cmdw_last_update="7/25/2007 3:10:52 PM">...

So you can do

#if I got that previous in to the data variable
>> data.first.filter_id
=> "56187382" 

In this case you would not care what data types there are, but if you would then parsing would have to be more sofisticated, this is just quickest and dertiest way.