Last active
August 29, 2015 14:05
-
-
Save sharmaabhinav/d7a315adf61fabe69195 to your computer and use it in GitHub Desktop.
This file contains 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' | |
class Temprature | |
DROPBOX_FILE_URL = 'https://www.dropbox.com/s/zih6f1psx82ehe1/miami-temperature.txt?dl=1' | |
def initialize | |
get_data_from_dropbox_file | |
end | |
def least_difference_day | |
min_element = @data.min | |
@data.index(min_element) + 1 | |
end | |
def max_difference_day | |
max_element = @data.max | |
@data.index(max_element) + 1 | |
end | |
private | |
def get_data_from_dropbox_file | |
parse_response(URI.parse(DROPBOX_FILE_URL).read) | |
end | |
def parse_response(data) | |
lines = data.split("\n") | |
@data = [] | |
lines.each do |line| | |
if line != '' | |
columns = line.split(" ")[0..2].map {|x| x.to_i} | |
@data << columns[1] - columns[2] if columns[0].to_i.between?(1,31) | |
end | |
end | |
end | |
end | |
temp = Temprature.new | |
print temp.max_difference_day.to_s + " " + temp.least_difference_day.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment