Examples - nolim1t/dont-overstay GitHub Wiki

This example summarizes the response

require 'dont-overstay'

def find_country(code, countries)
  found = -1
  counter = 0
  countries.each{|country|
    if country[:code] == code then
      found = counter
    end
    counter += 1
  }
  found
end

d = Daytracker.new
result = d.query
country_summary = []
if result[:status] == "OK" then
  countries = result[:countries]
  countries.each{|country|
    from_summary = find_country(country[:code], country_summary)
    if from_summary == -1  then
      country_summary << country
    else
      # Add new totals
      total_visit = country[:length].to_i + country_summary[from_summary][:length].to_i
      country_summary[from_summary][:length] = total_visit.to_i
    end
  }
  puts country_summary.inspect
end