Class: Mcoin::Command::Ticker

Inherits:
Base
  • Object
show all
Includes:
HasMarket, HasType, Saveable
Defined in:
lib/mcoin/command/ticker.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Saveable

#database, included, #save?

Methods included from HasType

included

Methods included from HasMarket

included

Methods inherited from Base

description, #initialize, option, #parse!

Constructor Details

This class inherits a constructor from Mcoin::Command::Base

Instance Attribute Details

#optionObject (readonly)

Returns the value of attribute option.



11
12
13
# File 'lib/mcoin/command/ticker.rb', line 11

def option
  @option
end

Instance Method Details

#executeObject

Raises:

  • (OptionParser::MissingArgument)


15
16
17
18
19
# File 'lib/mcoin/command/ticker.rb', line 15

def execute
  raise OptionParser::MissingArgument, :market if option.market.nil?
  print
  save if save?
end

#marketsObject



30
31
32
33
34
35
36
# File 'lib/mcoin/command/ticker.rb', line 30

def markets
  @markets ||= option.market.map do |name|
    Market
      .pick(name)
      .new(option.type, option.currency)
  end
end


21
22
23
24
# File 'lib/mcoin/command/ticker.rb', line 21

def print
  tickers = Parallel.map(markets, :fetch).map(&:to_ticker)
  Printer.new(tickers).print
end

#saveObject



26
27
28
# File 'lib/mcoin/command/ticker.rb', line 26

def save
  database.save(markets.map(&:to_ticker).map(&:to_influx))
end