title: Rails date range JSON data
body: <p>I'm looking to have a date range from <code>1.month.ago..Date.today</code>, then for each day select the maximum temperature (so should get 30 individual numbers), then sum up the results.</p>
  
  <p>I obtain the data in JSON format which is structured like this</p>
  
  <pre><code>{"status": "ok", "data": [{"temperature": 22.4, "date": "20160815-0345"}}
  </code></pre>
  
  <p>I parse the data through a loop.</p>
  
  <pre><code>@data['data'].each do |d|
   maxTotal &lt;&lt; [DateTime.parse(d['date']), d['temperature']]
  end
  </code></pre>
  
  <p>But fall short on how to select the maximum for each day and then sum it up.</p>
  
  <pre><code>@total = maxTotal { |a| a[0].to_date == (1.month.ago.to_date) }.max { |a,b| a[1] &lt;=&gt; b[1] }.sum[1]
  </code></pre>