Class: Coinpare::Commands::Coins
- Inherits:
-
Coinpare::Command
- Object
- Coinpare::Command
- Coinpare::Commands::Coins
- Defined in:
- lib/coinpare/commands/coins.rb
Constant Summary
Constants inherited from Coinpare::Command
Coinpare::Command::DEFAULT_INTERVAL, Coinpare::Command::SYMBOLS
Instance Method Summary collapse
- #execute(output: $stdout) ⇒ Object
-
#initialize(names, options) ⇒ Coins
constructor
A new instance of Coins.
Methods inherited from Coinpare::Command
#add_color, #banner, #config, #cursor, #editor, #number_to_currency, #percent, #percent_change, #pick_arrow, #pick_color, #precision, #round_to, #screen, #shorten_currency, #timestamp
Constructor Details
#initialize(names, options) ⇒ Coins
Returns a new instance of Coins.
15 16 17 18 19 20 21 22 |
# File 'lib/coinpare/commands/coins.rb', line 15 def initialize(names, ) @names = names @options = @pastel = Pastel.new @timers = Timers::Group.new @spinner = TTY::Spinner.new(":spinner Fetching data...", format: :dots, clear: true) end |
Instance Method Details
#execute(output: $stdout) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/coinpare/commands/coins.rb', line 24 def execute(output: $stdout) pager = TTY::Pager.new(output: output) @spinner.auto_spin if @options["watch"] output.print cursor.hide interval = @options["watch"].to_f > 0 ? @options["watch"].to_f : DEFAULT_INTERVAL @timers.now_and_every(interval) { display_coins(output, pager) } loop { @timers.wait } else display_coins(output, pager) end ensure @spinner.stop if @options["watch"] @timers.cancel output.print cursor.clear_screen_down output.print cursor.show end end |