Top Level Namespace
Defined Under Namespace
Modules: Rcbp
Instance Method Summary collapse
- #colorize(text, color_code) ⇒ Object
- #getBuyPrice ⇒ Object
- #getHistoricalPrice ⇒ Object
- #getPrice(url) ⇒ Object
- #getSellPrice ⇒ Object
- #getSpotPrice ⇒ Object
- #setColor(text) ⇒ Object
Instance Method Details
#colorize(text, color_code) ⇒ Object
41 42 43 |
# File 'lib/rcbp.rb', line 41 def colorize(text, color_code) "\e[#{color_code}m#{text}\e[0m" end |
#getBuyPrice ⇒ Object
25 26 27 |
# File 'lib/rcbp.rb', line 25 def getBuyPrice return getPrice("https://api.coinbase.com/v1/prices/buy?qty=1") end |
#getHistoricalPrice ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/rcbp.rb', line 33 def getHistoricalPrice csv = String.new open("https://api.coinbase.com/v1/prices/historical") do |d| csv = CSV.parse(d.read, :col_sep => ",", :headers => "false") return csv[200][1] end end |
#getPrice(url) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rcbp.rb', line 8 def getPrice(url) amount = String.new currency = String.new open(url) do |d| json = JSON.parse(d.read) amount = json["amount"] currency = json["currency"] end return amount end |
#getSellPrice ⇒ Object
29 30 31 |
# File 'lib/rcbp.rb', line 29 def getSellPrice return getPrice("https://api.coinbase.com/v1/prices/sell?qty=1") end |
#getSpotPrice ⇒ Object
21 22 23 |
# File 'lib/rcbp.rb', line 21 def getSpotPrice return getPrice("https://api.coinbase.com/v1/prices/spot_rate") end |
#setColor(text) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/rcbp.rb', line 45 def setColor(text) # If price went down, set text to red and vice versa to green if getHistoricalPrice.to_f >= getSpotPrice.to_f colorize(text, 31) else colorize(text, 32) end end |