Class: Satoshi::Ticker

Inherits:
Object
  • Object
show all
Defined in:
lib/satoshi/ticker.rb

Constant Summary collapse

@@stop_bool =
false
@@input =
" "
@@coin_array =
[]

Class Method Summary collapse

Class Method Details

.coin_arrayObject



98
99
100
# File 'lib/satoshi/ticker.rb', line 98

def self.coin_array
  @@coin_array
end

.coin_array=(array) ⇒ Object



94
95
96
# File 'lib/satoshi/ticker.rb', line 94

def self.coin_array=(array)
  @@coin_array = array
end

.get_and_display_price(coin) ⇒ Object

def self.ticker_for_coin(coin)

puts "press control + c to stop"
puts "-------------------------"
puts "-------------------------"
  #Timeout::timeout(20) do
    self.get_and_display_price(coin)
    self.input = gets.chomp.to_s
    case self.input
    when "exit"
      Satoshi::Cli.exit
    when "search"
      self.stop_bool = true
    when "stop"
      self.stop_bool = true
      Satoshi::Cli.info_menu(coin)
    else
      self.ticker_for_coin(coin)
    end
  #end

end



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/satoshi/ticker.rb', line 29

def self.get_and_display_price(coin)
  Thread.new do
    while @@stop_bool == false
      puts "-------------------------" if self.coin_array[0] == coin
      new_price = Satoshi::Scraper.scrape_new_price_for_coin(coin.info_link).to_f
      string = "#{coin.name} $#{new_price}"
      if new_price > coin.last_price
        ##green
        string = string.green
      elsif new_price < coin.last_price
        ##gray
        string = string.red
      else
        string = string.black
      end
      puts string
      coin.last_price = new_price
      sleep(5)
    end
  end
end

.inputObject



90
91
92
# File 'lib/satoshi/ticker.rb', line 90

def self.input
  @@input
end

.input=(text) ⇒ Object



86
87
88
# File 'lib/satoshi/ticker.rb', line 86

def self.input=(text)
  @@input = text
end

.loop_on_new_tread_for_ticker_arrayObject



51
52
53
54
55
# File 'lib/satoshi/ticker.rb', line 51

def self.loop_on_new_tread_for_ticker_array
  Thread.new do
    self.coin_array.each{ |coin| self.get_and_display_price(coin)}
  end
end

.stop_boolObject



82
83
84
# File 'lib/satoshi/ticker.rb', line 82

def self.stop_bool
  self.stop_bool
end

.stop_bool=(bool) ⇒ Object



78
79
80
# File 'lib/satoshi/ticker.rb', line 78

def self.stop_bool=(bool)
  @@stop_bool = bool
end

.ticker_for_coin_array(coin_called_from) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/satoshi/ticker.rb', line 57

def self.ticker_for_coin_array(coin_called_from)
    puts "Enter stop, search ,or exit to stop ticker".red
    puts "-------------------------"
    puts "-------------------------"
      #Timeout::timeout(20) do
        self.loop_on_new_tread_for_ticker_array
        self.input = gets.chomp.to_s
        case self.input
        when "exit"
          Satoshi::Cli.exit
        when "search"
          Satoshi::Cli.first_prompt_for_coins
        when "stop"
          self.stop_bool = true
          Satoshi::Cli.info_menu(coin_called_from)
        else
          self.ticker_for_coin_array(coin_called_from)
        end
      #end
end