Method: Heart::MetricsController#fetch

Defined in:
app/controllers/heart/metrics_controller.rb

#fetchObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/heart/metrics_controller.rb', line 17

def fetch
  method = "fetch_" + params[:attribute].to_s
  params[:enddate] = (params[:enddate].nil?) ? params[:fulldate] : params[:enddate]
  startdate = Date.parse(params[:fulldate].to_s)
  enddate = Date.parse(params[:enddate].to_s)
  startdate.upto(enddate) do |date|
    @metric = Heart::Metric.find_or_create(date,0)
    isometric = Heart::Isometric.find_or_create(date,0)

    @metric.send(method)

    @metric.save
    isometric.send(params[:attribute.to_s]+"=", Time.now) unless method == "fetch_all"
    isometric.save unless method == "fetch_all"
  end
end