Ensure continuous date range
Several aspects of your code could use improvement:


It would be nice if the code were packaged in a function.
Date.new(Integer(dates.first[0..3]), Integer(dates.first[4..5]), Integer(dates.first[6..7])) is rather verbose and ugly.

I recommend DateTime.strptime for date parsing — it's the inverse of strftime.
You can call Range#map directly; you don't need to do to_a first.
dates.map { |d| range.index(d) } could be problematic for performance, since it is O(n2).

Instead, you should make a Hash.


Here is one solution:

require 'date_core'

DATE_FMT = '%Y%m%d'

def filled_date_series(dates, values, default_value=0)
  data = Hash[dates.zip(values)]
  datetime_range = (DateTime.strptime(dates.first, DATE_FMT) ..
                    DateTime.strptime(dates.last,  DATE_FMT))
  date_range = datetime_range.map { |dt| dt.strftime(DATE_FMT) }
  [
    date_range,
    date_range.map { |d| data[d] || default_value }
  ]
end

dates = ["20161010", "20161013"]
values = [5, 3]
range, filled_values = filled_date_series(dates, values)