ranNUM 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/bin/SP500.txt +500 -0
  3. data/bin/owmid.txt +9999 -0
  4. data/lib/ranNUM.rb +63 -0
  5. metadata +46 -0
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+ require 'net/http'
3
+
4
+ class RAN
5
+ #get stock data
6
+ def self.get_yql_data(ticker)
7
+ 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="
8
+ resp = Net::HTTP.get_response(URI.parse(url))
9
+ JSON.parse(resp.body)
10
+ end
11
+ def self.s_SYMBOL
12
+ random_string_stocks = rand(500)
13
+ IO.readlines("bin/SP500.txt")[random_string_stocks]
14
+ end
15
+ #get weather data
16
+ def self.get_owm_data(city_id, api_key)
17
+ #url = "http://api.openweathermap.org/data/2.5/weather?id=#{city_id}&units=imperial&APPID=#{api_key}" #in fahrenheit
18
+ url = "http://api.openweathermap.org/data/2.5/weather?id=#{city_id}&units=metric&APPID=#{api_key}" #in celcius
19
+ #url = "http://api.openweathermap.org/data/2.5/weather?id=#{city_id}&APPID=#{api_key}" #in kelvin
20
+ resp = Net::HTTP.get_response(URI.parse(url))
21
+ JSON.parse(resp.body)
22
+ end
23
+ def self.w_TEMP
24
+ random_string_weather = rand(10000)
25
+ city = IO.readlines("bin/owmid.txt")[random_string_weather]
26
+ api_owm = "4610a14e77ea7d2522ef38eed4bbee0c"
27
+ output_weather = get_owm_data(city, api_owm)
28
+ output_weather["main"]["temp"]
29
+ end
30
+ def self.y_STOCK
31
+ output_stock = RAN.get_yql_data(RAN.s_SYMBOL)
32
+ output_stock["query"]["results"]["quote"]["Ask"]
33
+ end
34
+ def self.number
35
+ RAN.y_STOCK.to_f*RAN.w_TEMP.to_f+1
36
+ end
37
+ def self.num(rnNUM)
38
+ tensecond_RN = RAN.number
39
+ begin
40
+ #puts tensecond_RN
41
+ tensecond_RN /=10
42
+ end while tensecond_RN > rnNUM
43
+ tensecond_RN.abs
44
+ end
45
+ end
46
+
47
+ #print random stock symbol
48
+ #puts RAN.s_SYMBOL
49
+
50
+ #print random temperature
51
+ #puts RAN.w_TEMP
52
+
53
+ #print random stock price
54
+ #puts RAN.y_STOCK
55
+
56
+ #prints random stock * random temperature
57
+ #puts RAN.number
58
+
59
+ #prints a random number equal to or below the number in parentheses
60
+ #puts RAN.num(10)
61
+
62
+ #prints a random number equal to or below the number in parentheses rounded
63
+ puts RAN.num(10).round
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ranNUM
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Colby Taperts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple random number generator using random temperature and stock prices
14
+ email: colbytaperts@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - bin/SP500.txt
20
+ - bin/owmid.txt
21
+ - lib/ranNUM.rb
22
+ homepage: http://rubygems.org/gems/ranNUM
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.5.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Random Number generator
46
+ test_files: []