У меня есть массив с именем "thing1" и класс с именем "Sr", атрибуты которого соответствуют элементам массива "thing1". Мне нужно назначить каждый элемент вещи 1 каждому соответствующему атрибуту объекта Sr.
things1.each_with_index do |line,index|
if index == 0
next
elsif
array = line.strip.split('|')
array.each do |attribute|
# here is where I am stuck !!!!!!!
end
, поскольку я получил следующее в pry
[5] pry(main)> array= l.strip.split('|')
=> ["324184-101003318953",
"5118 ROBERTSON, HOUSTON TX 77009",
"HARRIS",
"H",
"NEAR NORTHSIDE",
"0311520000001",
"NE",
"NW",
"FRIDAY",
"1st Friday",
"FRIDAY-B",
"453V",
"Greater Northside MD",
"311 HelpLine",
"311 Call Handling",
"Unclassified 311 Web Request",
"311_Seniors",
"18",
"Closed",
"2019-01-01 00:02:10",
"2019-01-02 09:02:07",
"2019-01-03 09:34:08",
"1.02",
"Other - 324184",
"-95.35739000000",
"29.80668000000",
"29.80654129",
"-95.35715636",
"WAP"]
[6] pry(main)> array[0]
=> "324184-101003318953"
[7] pry(main)> array.size
=> 29
Here is the new Sr class attributes that I need to assign each of the 29 elements of the thing1 array
sr = Sr.new(:case_number => case_number, :sr_location => sr_location, :county => county, :district => district, :neighborhood => neighborhood, :tax_id => tax_id, :trash_quad => trash_quad,:recycle_quad => recycle_quad, :trash_day => trash_day, :heavy_trash_day => heavy_trash_day, :recycle_day => recycle_day, :key_map => key_map,:management_district => management_district, :department => department, :division => division, :sr_type => sr_type, :queue => queue, :sla => sla, :status => status, :sr_create_date => sr_create_date, :due_date => due_date, :date_closed => date_closed, :overdue => overdue, :title => title, :x => x, :y => y, :latitude = latitude, :longitude => longitude, :channel_type => channel_type, :created_at => created_at, :updated_at => updated_at )
sr.save
end