Created
December 23, 2016 17:34
-
-
Save panw/37952dc700fc3f0c8cd49f26bb84c1c6 to your computer and use it in GitHub Desktop.
Calculate how much Chipotle you could have had. Instead you wasted the moneyz on parking violations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
require 'json' | |
require 'pry' | |
# THE ADDRESS ON THE INTERNET YOU WANT TO FETCH DATA FROM | |
BASE_URL = "https://data.cityofnewyork.us/resource/uvbq-3m68.json" | |
# GET USER INPUT TO MAKE IT DYNAMIC | |
puts 'What is the license plate number you want to search for?' | |
user_input = gets.chomp | |
# ISSUE THE REQUEST | |
response = open("#{BASE_URL}?plate=#{user_input}").read | |
# RESPONSE IS A STRING SO WE PARSE IT TO TURN IT INTO ARRAY OF HASHES | |
violations = JSON.parse(response) | |
# RUBY WE ARE ALL FAMILIAR WITH | |
moneyz_lost = violations.reduce(0) { |sum, violation| sum + violation['fine_amount'].to_i } | |
num_chipotles = moneyz_lost/9 | |
# ENTERTAIN YOSELF | |
puts "You spent this much moneyz $#{moneyz_lost}" | |
puts "You could have had this many Chipotles #{num_chipotles}" | |
puts "Try to drive BETTER" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment