Class: MinerMover::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/miner_mover/run.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg_file: nil, timer: nil) ⇒ Run

Returns a new instance of Run.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/miner_mover/run.rb', line 24

def initialize(cfg_file: nil, timer: nil)
  @cfg_file = self.class.cfg_file(cfg_file)
  @cfg = Config.process @cfg_file
  main  = @cfg.fetch :main
  @miner = @cfg.fetch :miner
  @mover = @cfg.fetch :mover

  @num_miners = main.fetch :num_miners
  @num_movers = main.fetch :num_movers

  @time_limit = main.fetch :time_limit
  @ore_limit  = main.fetch :ore_limit
  @logging    = main.fetch :logging
  @debugging  = main.fetch :debugging

  @timer = timer || Timer.new
end

Instance Attribute Details

#cfgObject

Returns the value of attribute cfg.



21
22
23
# File 'lib/miner_mover/run.rb', line 21

def cfg
  @cfg
end

#cfg_fileObject

Returns the value of attribute cfg_file.



21
22
23
# File 'lib/miner_mover/run.rb', line 21

def cfg_file
  @cfg_file
end

#debuggingObject

Returns the value of attribute debugging.



19
20
21
# File 'lib/miner_mover/run.rb', line 19

def debugging
  @debugging
end

#loggingObject

Returns the value of attribute logging.



19
20
21
# File 'lib/miner_mover/run.rb', line 19

def logging
  @logging
end

#minerObject

Returns the value of attribute miner.



21
22
23
# File 'lib/miner_mover/run.rb', line 21

def miner
  @miner
end

#moverObject

Returns the value of attribute mover.



21
22
23
# File 'lib/miner_mover/run.rb', line 21

def mover
  @mover
end

#num_minersObject

Returns the value of attribute num_miners.



20
21
22
# File 'lib/miner_mover/run.rb', line 20

def num_miners
  @num_miners
end

#num_moversObject

Returns the value of attribute num_movers.



20
21
22
# File 'lib/miner_mover/run.rb', line 20

def num_movers
  @num_movers
end

#ore_limitObject

Returns the value of attribute ore_limit.



22
23
24
# File 'lib/miner_mover/run.rb', line 22

def ore_limit
  @ore_limit
end

#time_limitObject

Returns the value of attribute time_limit.



22
23
24
# File 'lib/miner_mover/run.rb', line 22

def time_limit
  @time_limit
end

#timerObject

Returns the value of attribute timer.



21
22
23
# File 'lib/miner_mover/run.rb', line 21

def timer
  @timer
end

Class Method Details

.cfg_file(filename = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/miner_mover/run.rb', line 7

def self.cfg_file(filename = nil)
  f = filename || ARGV.shift || Config.recent
  if f.nil?
    raise(Config::Error, "no config file")
  elsif !File.exist? f
    raise(Config::Error, "can't find file #{f.inspect}")
  elsif !File.readable? f
    raise(Config::Error, "can't read file #{f.inspect}")
  end
  f
end

Instance Method Details

#cfg_banner!(duration: 0) ⇒ Object



42
43
44
45
46
47
# File 'lib/miner_mover/run.rb', line 42

def cfg_banner!(duration: 0)
  MinerMover.puts "USING: #{@cfg_file}"
  pp @cfg
  sleep duration if duration > 0
  self
end

#debug(msg) ⇒ Object



80
81
82
# File 'lib/miner_mover/run.rb', line 80

def debug msg
  @debugging and MinerMover.log @timer, '(debug) ', msg
end

#log(msg) ⇒ Object



76
77
78
# File 'lib/miner_mover/run.rb', line 76

def log msg
  @logging and MinerMover.log @timer, ' (main) ', msg
end

#new_minerObject



60
61
62
# File 'lib/miner_mover/run.rb', line 60

def new_miner
  Miner.new(**@miner)
end

#new_moverObject



64
65
66
# File 'lib/miner_mover/run.rb', line 64

def new_mover
  Mover.new(**@mover)
end

#ore_limit?(ore_mined) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/miner_mover/run.rb', line 68

def ore_limit?(ore_mined)
  Ore.block(ore_mined) > @ore_limit
end

#start!Object



49
50
51
52
# File 'lib/miner_mover/run.rb', line 49

def start!
  @timer.restart
  self
end

#time_limit?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/miner_mover/run.rb', line 72

def time_limit?
  @timer.elapsed > @time_limit
end

#timestamp!Object



54
55
56
57
58
# File 'lib/miner_mover/run.rb', line 54

def timestamp!
  dash = '-' * 70
  str = [dash, Timer.timestamp, dash].join(MinerMover::LINE_SEP)
  MinerMover.puts str
end