class RAN

Public Class Methods

get_owm_data(city_id, api_key) click to toggle source

get weather data

# File lib/ranNUM.rb, line 69
def self.get_owm_data(city_id, api_key)
    url = "http://api.openweathermap.org/data/2.5/weather?id=#{city_id}&units=imperial&APPID=#{api_key}" #in fahrenheit
    #url = "http://api.openweathermap.org/data/2.5/weather?id=#{city_id}&units=metric&APPID=#{api_key}" #in celcius
    #url = "http://api.openweathermap.org/data/2.5/weather?id=#{city_id}&APPID=#{api_key}" #in kelvin
    resp = Net::HTTP.get_response(URI.parse(url))
    JSON.parse(resp.body)
end
get_yql_data(ticker) click to toggle source

get stock data

# File lib/ranNUM.rb, line 54
def self.get_yql_data(ticker)
    url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%3D%22#{ ticker }%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback="
    resp = Net::HTTP.get_response(URI.parse(url))
    JSON.parse(resp.body)
end
nnstocksfile() click to toggle source
# File lib/ranNUM.rb, line 40
def self.nnstocksfile
    nnstocks_path = File.join( File.dirname(__FILE__), './textfiles/nnstocks.txt' )
    File.open( nnstocks_path )
end
num(num) click to toggle source
# File lib/ranNUM.rb, line 117
def self.num(num)
    a_ran_num = RAN.number(num)
    a_ran_num_sq = a_ran_num ** 5 * 10
    while a_ran_num_sq > num
        a_ran_num_sq /=num
    end
    a_ran_num_sq.abs
end
number(n = 11) click to toggle source
# File lib/ranNUM.rb, line 112
def self.number(n = 11)
     n = Math.sqrt(n)**2
    (rand(n)*RAN.y_STOCK.to_f*RAN.w_TEMP.to_f+1)*(rand(n)*RAN.s_SYMBOL2.to_f+1)
end
owmapi() click to toggle source
# File lib/ranNUM.rb, line 48
def self.owmapi

owm_path2 = File.join( File.dirname(__FILE__), './textfiles/owmapi.txt' )
    File.read( owm_path2)
end
owmfile() click to toggle source
# File lib/ranNUM.rb, line 44
def self.owmfile
    owm_path = File.join( File.dirname(__FILE__), './textfiles/owmid.txt' )
    File.open( owm_path )
end
s_SYMBOL() click to toggle source
# File lib/ranNUM.rb, line 59
def self.s_SYMBOL
    random_string_stocks = rand(500)
    IO.readlines(RAN.sp500file)[random_string_stocks]
end
s_SYMBOL2() click to toggle source
# File lib/ranNUM.rb, line 64
def self.s_SYMBOL2
    random_string_stocks2 = rand(5910)
    IO.readlines(RAN.nnstocksfile)[random_string_stocks2]
end
sp500file() click to toggle source
# File lib/ranNUM.rb, line 36
def self.sp500file
    sp500_path = File.join( File.dirname(__FILE__), './textfiles/SP500.txt' )
    File.open( sp500_path )
end
w_TEMP() click to toggle source
# File lib/ranNUM.rb, line 77
def self.w_TEMP
    random_string_weather = rand(10000)
    city = IO.readlines(RAN.owmfile)[random_string_weather]
    api_owm = RAN.owmapi
    output_weather = get_owm_data(city, api_owm)
    weathertemp = output_weather["main"]["temp"]
        unless weathertemp.nil? 
            weathertemp
        else
            sleep(1)
            RAN.w_TEMP
        end
end
y_STOCK() click to toggle source
# File lib/ranNUM.rb, line 91
def self.y_STOCK
    output_stock = RAN.get_yql_data(RAN.s_SYMBOL)
    stockprice1 = output_stock["query"]["results"]["quote"]["Ask"]
        unless stockprice1.nil? 
            stockprice1
        else
            RAN.y_STOCK
        end
end
y_STOCK2() click to toggle source
# File lib/ranNUM.rb, line 101
def self.y_STOCK2
    output_stock = RAN.get_yql_data(RAN.s_SYMBOL2)
    stockprice2 = output_stock["query"]["results"]["quote"]["Ask"]
        unless stockprice2.nil? 
            stockprice2
        else
            RAN.y_STOCK2
        end
end