ruby on rails - How to save data from a file which doesn't have column names? -
i have table following fields:
# == schema information # # table name: scheme_details # # id :integer not null, primary key # scheme_id :integer not null # nav_date :datetime # nav_price :float # repurchase_price :float # sale_price :float # closing_date :datetime # net_change :float # prev_nav :float # prev_nav_date :datetime # upd_flag :string(1) # created_at :datetime not null # updated_at :datetime not null # change :float #
now getting data file ace
file extension ftp server, doesn't have column names.
following sample data of file.
<<row>>1|5/24/2016 12:00:00 am|1000.49|1000.49|1000.49||0|0|1000.49|5/23/2016 12:00:00 am|a<</row>> <<row>>2|5/24/2016 12:00:00 am|2350.0193|2350.0193|2350.0193||0.0210084954593086|0.493599999999788|2349.5257|5/23/2016 12:00:00 am|a<</row>> <<row>>3|5/24/2016 12:00:00 am|1005.4653|1005.4653|1005.4653||0.0210096133902824|0.211199999999963|1005.2541|5/23/2016 12:00:00 am|a<</row>> <<row>>4|5/24/2016 12:00:00 am|1001.2549|1001.2549|1001.2549||0.0210080549857693|0.210300000000075|1001.0446|5/23/2016 12:00:00 am|a<</row>> <<row>>9|5/24/2016 12:00:00 am|1005.428|1005.428|1005.428||0.0208611403115122|0.209699999999998|1005.2183|5/23/2016 12:00:00 am|a<</row>> <<row>>10|5/24/2016 12:00:00 am|2226.3533|2226.3533|2226.3533||0.0208725620468016|0.464600000000246|2225.8887|5/23/2016 12:00:00 am|a<</row>> <<row>>11|5/24/2016 12:00:00 am|1001.2478|1001.2478|1001.2478||0.0208683199024505|0.208899999999971|1001.0389|5/23/2016 12:00:00 am|a<</row>> <<row>>14|5/24/2016 12:00:00 am|14.369|14.369|14.369||-0.567434779600033|-0.0820000000000007|14.451|5/23/2016 12:00:00 am|a<</row>> <<row>>15|5/24/2016 12:00:00 am|33.37|33.37|33.37||-0.566150178784281|-0.190000000000005|33.56|5/23/2016 12:00:00 am|a<</row>> <<row>>22|5/24/2016 12:00:00 am|15.87|15.87|15.87||-0.501567398119123|-0.0800000000000001|15.95|5/23/2016 12:00:00 am|a<</row>> <<row>>23|5/24/2016 12:00:00 am|64.37|64.37|64.37||-0.540791100123601|-0.349999999999994|64.72|5/23/2016 12:00:00 am|a<</row>> <<row>>115|5/24/2016 12:00:00 am|10.1146|10.1146|10.1146||-0.00197730058924853|-0.00020000000000131|10.1148|5/23/2016 12:00:00 am|a<</row>> <<row>>116|5/24/2016 12:00:00 am|25.8745|25.8745|25.8745||-0.00193236714975395|-0.000499999999998835|25.875|5/23/2016 12:00:00 am|a<</row>> <<row>>117|5/24/2016 12:00:00 am|10.3195|10.3195|10.3195||-0.00193804083451587|-0.000199999999999534|10.3197|5/23/2016 12:00:00 am|a<</row>> <<row>>118|5/24/2016 12:00:00 am|10.317|10.317|10.317||-0.0019385104485668|-0.000199999999999534|10.3172|5/23/2016 12:00:00 am|a<</row>> <<row>>119|5/24/2016 12:00:00 am|10.0863|10.0863|10.0863||-0.00198284836166692|-0.000199999999999534|10.0865|5/23/2016 12:00:00 am|a<</row>> <<row>>160|5/24/2016 12:00:00 am|10.0729|10.0729|10.0729||0.0148936592727928|0.00150000000000006|10.0714|5/23/2016 12:00:00 am|a<</row>> <<row>>165|5/24/2016 12:00:00 am|17.3863|17.3863|17.3863||0.0155318806231003|0.00269999999999726|17.3836|5/23/2016 12:00:00 am|a<</row>> <<row>>166|5/24/2016 12:00:00 am|10.0315|10.0315|10.0315||0|0|10.0315|5/23/2016 12:00:00 am|a<</row>>
i able parse file , remove unwanted data row
, split data using |
.
problem facing how map data column names sample data file doesn't have column names , data.
one solution had adding dummy column names row on top of file through able map data.
but not sure if right way so.
any or suggestion on how solve problem helpful.
thank you!
note: if need see code have made happy provide.
you can define array
push splited values inside that, each row.
now map according index values of array schema.
Comments
Post a Comment