Skip to content

Instantly share code, notes, and snippets.

@stevencwarren
Created September 13, 2012 03:27
Show Gist options
  • Save stevencwarren/3711661 to your computer and use it in GitHub Desktop.
Save stevencwarren/3711661 to your computer and use it in GitHub Desktop.
def chart_health_tracker_data(health_tracker_entry_list, header, method, days_back = 7)
start_day = Date.today - days_back + 1
day_labels = []
exercise_points = []
calorie_points = []
weight_points = []
table = [header]
#iterate through the days and store points
start_day.step(start_day + days_back - 1, 1) {|day|
result = 0
health_tracker_entry = health_tracker_entry_list.detect {|element| element.date == day }
if health_tracker_entry
result = health_tracker_entry.send(method)
end
table << [day.strftime("%a"), result]
}
table
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment