A
Alpha Blue
I have an array that contains 36 objects. The composition of those
objects includes a date, a team, and a time. It is being parsed from
another site.
[0] = Sept 2
[1] = vsSouthern Miss
[2] = 7:30 PM ET
[3] = Sept 9
[4] = @Florida
[5] = 7:30 PM ET
etc.
Every 3 objects should be combined into a specific hash row.
[0][:date] = Sept 2
[0][:team] = vsSouthern Miss
[0][:time] = 7:30 PM ET
[1][:date] = Sept 9
[1][:team] = @Florida
[1][:time] = 7:30 PM ET
etc.
I'm having trouble accomplishing this. Each schedule might have more
than 36 objects in the array, but the divisor will always be 3 in terms
of what type of information is presented. So, a team might have an
array of 39 objects or 42 objects but in the end, the objects are a
date, team, and a time.
I've tried numerous things, even adding a new class method:
class Array
def to_spec_hash(other)
Hash[ *(0...self.size()).inject([]) { |arr, ix| arr.push(self[ix],
other[ix]) } ]
end
end
and then trying to use:
%W{ date team time }.to_spec_hash( %W{ value1 value2 value3 etc. } )
but I'd have to iterate over date team and time according to how many
rows of data divided by 3 would be and the same for the values. Again,
I know it's sloppy.
I'm sure there's a much faster and a cleaner way of accomplishing this
but I'm lacking sleep and therefore not thinking as clearly.
Any help would be appreciated.
objects includes a date, a team, and a time. It is being parsed from
another site.
[0] = Sept 2
[1] = vsSouthern Miss
[2] = 7:30 PM ET
[3] = Sept 9
[4] = @Florida
[5] = 7:30 PM ET
etc.
Every 3 objects should be combined into a specific hash row.
[0][:date] = Sept 2
[0][:team] = vsSouthern Miss
[0][:time] = 7:30 PM ET
[1][:date] = Sept 9
[1][:team] = @Florida
[1][:time] = 7:30 PM ET
etc.
I'm having trouble accomplishing this. Each schedule might have more
than 36 objects in the array, but the divisor will always be 3 in terms
of what type of information is presented. So, a team might have an
array of 39 objects or 42 objects but in the end, the objects are a
date, team, and a time.
I've tried numerous things, even adding a new class method:
class Array
def to_spec_hash(other)
Hash[ *(0...self.size()).inject([]) { |arr, ix| arr.push(self[ix],
other[ix]) } ]
end
end
and then trying to use:
%W{ date team time }.to_spec_hash( %W{ value1 value2 value3 etc. } )
but I'd have to iterate over date team and time according to how many
rows of data divided by 3 would be and the same for the values. Again,
I know it's sloppy.
I'm sure there's a much faster and a cleaner way of accomplishing this
but I'm lacking sleep and therefore not thinking as clearly.
Any help would be appreciated.